Message from JavaScript discussions

June 2017

— Which MEANS only statics AND instance methods within the class definition itself have access to private vars

Message permanent page


And NOT external (modified in runtime for example) instance methods: = [rogue function]

— Which means that the new syntax offers no new attack surface

— There is a buitin for getting all symbols, isn't there?


— Yeah, I remember reading about it on MDN

— This does make sense

— Well, symbols is only one method

— I could also have used WeakMap

— I never meant attack surface, more an issue of smelly code haha

— I guess it depends on use case


const priv = new WeakMap();

class MyClass {
constructor () {
priv.set(this, { value: 42 });
digitSum () {
return String(priv.get(this).value)
.split('').reduce((sum, digit) =>
sum + digit, 0);

Message permanent page