4 ms·
#1 is just FUD. JavaScript is JavaScript. Class in JS is a shorthand for function and functions prototypically delegate. That you're not writing in Java/Python/
by slightlyoff 14y ago
#1 is just FUD. JavaScript is JavaScript. Class in JS is a shorthand for function and functions prototypically delegate. That you're not writing in Java/Python/C#/Ruby should be pretty obvious.
#2 doesn't bear much relationship to reality. There will be near zero correlation between "class" and performance. What can (and today, does) change the performance of objects is having their shape change markedly after construction. V8, for instance, already includes heuristics to know when a class is "done" being constructed, allowing it to apply most of the typed-language tricks in the bag for objects which are entirely unfrozen. In current code, it's actually a de-optimizer to call Object.freeze() and there's no reason to think you'll get anything faster for using "class" than by writing code which doesn't change its shape very much.
You will, however, finally be able to read and share code more easily.
- MatthewPhillips 14y ago> That you're not writing in Java/Python/C#/Ruby should be pretty obvious. I don't think it's obvious at all that the keyword "class" is going to be fundamentally different from whatever OO language you are coming from. Isn't this the single biggest reason why many developers have difficulty learning JavaScript? > There will be near zero correlation between "class" and performance. There already is performance differences between constructor functions and Object.create (in terms of initialization, that is).
- slightlyoff 14y agoObject.create() creates no closure. You've already paid for in the context in which you're .create()-ing. In any case, performance optimization is what happens when something becomes common enough to work its way into benchmarks. And calling out a delta now that's probably not your bottleneck seems...um...less than useful.