This can be accomplished in ES 6, but I still think its largely unnecessary except at the module-level:
let privateData = new WeakMap(); class Foo { constructor () { privateData.set(this, { hidden: 'bar' }); } // this is a prototype function, we could equivalently define // it outside the class definition as Foo.prototype.getPrivate // and it would be the same getPrivate () { return privateData.get(this).hidden; } } console.log(new Foo().getPrivate()); // logs 'bar' Importance of the WeakMap:
It allows arbitrary objects as keys, but those keys are weakly held: they don't count as references to prevent the key object from being garbage collected. Once the class is exported, code outside the module its defined in can't access privateData. See this for more info.