3 ms·
Also in Lua you can change the prototype of constructed objects, by just calling setmetatable() on them again; while in Javascript you can't --- once the object
by david-given 11y ago
Also in Lua you can change the prototype of constructed objects, by just calling setmetatable() on them again; while in Javascript you can't --- once the object's been constructed, that's it.
http://stackoverflow.com/questions/7015693/how-to-set-the-prototype-of-a-javascript-object-that-has-already-been-instantiat http://stackoverflow.com/questions/7015693/how-to-set-the-pr...
I ran into this a little while back while trying to port some Lua code to Javascript. It was very annoying.
- masklinn 11y ago> while in Javascript you can't --- once the object's been constructed, that's it. ES2015 standardised the read/write __proto__ attribute (which most browsers had implemented for a long time), and added a #setPrototypeOf call. The first answer of your link notes exactly that.
- david-given 11y agoIt's added as an optional feature, as the first sentence of that answer describes: > ...the answer below is no longer accurate. _proto_ is being added to ecmascript6 as "normative optional" which means it isn't required to be implemented... It can't always be polyfilled, either, which makes the feature effectively useless. I'm not even sure why they added it as such a half-hearted feature to ES6; I suspect politics (Brendon Eich appears to have been dead set against having mutable protos for years).
- masklinn 11y ago> It's added as an optional feature Fuck's sake mate, Object.setPrototypeOf is not optional (and __proto__ is only optional for non-browser environments). > It can't always be polyfilled, either, which makes the feature effectively useless. That's breathtaking dishonesty.