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.
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.
So, is there any possibility to use private data in ES6 class compatible with traceur compiler?