And here it is (with what it can be done for 200 years):
ES6:
var say = Symbol() class Cat { constructor(){ this[say]() // call private } [say](){ alert('im private') } }
ES5:
var say = Math.random() // like Symbol() function Cat(){ this[say]() // call private methods } Cat.prototype[say] = function(){ alert('im a private') }
An example of using ES6:
var handlers = Symbol() class EventEmitter { constructor(){ this[handlers] = [] } on(handler){ this[handlers].push(handler) } emit(){ for(let handler of this[handlers]) handler() } } class Cat extends EventEmitter { } var q = new Cat() q.on // function q.emit // function q.handlers // undefined cuz PRIVATE ;)
And it is not necessary to learn the names of properties from the implementation of a class, such as the internal property of handlers, for fear of accidentally blocking them in the classes of heirs. I have been using private for 6 years now. And no problems with leaks. I do not understand people who say that there is no private javascript.
Enjoy;)