Answer the question
In order to leave comments, you need to log in
Es6 encapsulation missing?
Previously, I declared private properties and methods like this:
function MyClass () {
var privateProperty = 'value';
var privateMethod = function () {
console.log ('Hi, I am privateMethod');
};
this.publicMethod = function () {
privateMethod ();
return privateProperty;
};
}
class MyClass {
constructor () {
// F**k yeah, я использую Es6... Как нет приватных свойств? o.O
var privateProperty = 'value';
var privateMethod = function () {
console.log ('Hi, I am privateMethod');
};
// Нет-нет, постойте, какого ...?
}
}
Answer the question
In order to leave comments, you need to log in
Previously, I declared private properties and methods like this:
let privateStaticVar = 'foo';
// то что экспортируется - то публичное
export default class MyClass() {
constructor() {
}
}
// или
export default (function () {
let foo = 'foo';
return class FooBar {
constructor() {
}
};
}());
const privateFoo = Symbol('foo');
export default FooBar {
constructor(foo) {
this[privateFoo] = foo;
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question