It seems like classes in ES6 doesn't explicitly provide anything to have private data or methods.
Correct. The class
syntax is for normal classes with prototype methods. If you want private variables, you put them in the constructor as always:
class Deferred {
constructor() {
// initialise private data
var isPending = true;
var handlers = {
resolve: [],
reject: [],
notify: []
};
// Private method
function trigger(event, params) {
...
}
// initialise public properties
this.promise = new Promise(this);
// and create privileged methods
this.resolve = trigger.bind(null, 'resolve');
this.reject = trigger.bind(null, 'reject');
this.notify = trigger.bind(null, 'notify');
this.on = function(event, handler) {
…
};
}
}