Message from JavaScript discussions
June 2017
— It is non enumerable, which can be useful
Another thing you could do with the function syntax that you CAN'T do with class syntax is to 'redirect' the caller to use new if they omitted it:
function MyClass() {
if (!(this instanceof MyClass)) {
return new MyClass();
}
// ...
}
class syntax doesn't give you this at all
— Will return an object that is always instanceof MyClass
— Pretty awesome
— Wow
— That is sick!!
— A few builtins use this
— Including Symbol it seems
— That is like a factory-constructor hybrid
— Btw, IMO when it comes to making properties private, symbols will never be more useful than regular scope-restriction. Pipe interfaces of friend objects through a private event bus, problem solved. Instead of making every private friend-accessable member into some complicated system, you just make a single system private which enables that interface
— Yeah, I don't even use these structures that much
— I just prefer passing and returning functions rather than objects