4 ms·
Why would you introduce that distinction into what is an inherently dynamic language? "virtual" keyword in C++ is an option to avoid paying the cost for a polym
by astral303 13y ago
Why would you introduce that distinction into what is an inherently dynamic language? "virtual" keyword in C++ is an option to avoid paying the cost for a polymorphic call (so it can be inlined at compile time and/or no extra pointer dereference is done). It's a compromise to allow incremental cost of language features--but in JavaScript?
- mantrax3 13y agoThat's probably the one part that really didn't make sense. But maybe he did it for sport.
- mikegerwitz 13y agoThere are certain optimizations that I am able to perform by knowing if a function is virtual or not---this is especially important in the Trait implementation. However, the original intent is based on compelling rationale from C#. I cannot find the original article where the article explains the rationale, but aside from optimization benefits and self-documenting code, he makes the point that virtual methods are essentially callbacks/hooks into existing code; you therefore need to put careful thought into how to handle those virtual methods properly and expose the proper APIs.