Posts

Showing posts with the label ecmascript-5

How to implement private method in ES6 class with Traceur [duplicate]

How to implement private method in ES6 class with Traceur [duplicate] This question already has an answer here: I use Traceur Compiler to have advantage with ES6 features now. I want to implement this stuff from ES5: function Animal() { var self = this, sayHi; sayHi = function() { self.hi(); }; this.hi = function() {/* ... */} } Currently traceur does not support private and public keywords (from harmony). And ES6 class syntax does not allow to use simple var (or let ) statements in class body. private public var let The only way that I am find is to simulate privates before class declaration. Something like: var sayHi = function() { // ... do stuff }; class Animal { ... It is better then nothing but as expected you can not pass correct this to private method without apply -ing or bind -ing it every time. this apply bind So, is there any possibility to use private data in ES6 class compatible with traceur compiler? This question has been asked b...