I disagree about call and apply though. I prefer to never use:
new
this (one exception)
Object.create
bind
call
apply
When I avoid this list my code tends to be smaller and faster to execute. You don't need OOP in this language, thanks to lexical scope, to achieve decomposable reuse and reference sharing.
The one exception for this is event handlers where it is commonly necessary to access the event target without access to an explicit reference.
OOP code tends to require substantial boiler plate. Any speed improvement you notice likely comes from two things:
various mappings to references in memory (memory conservation and caching)
JIT optimizations
The memory reuse architecture for OOP in this language are prototypes. ES6 classes even desugar to prototypes. Prototype resolution is secondary to normal reference resolution in the lexical scope chain.
I prefer to code to the scope chain only (architecture of nested scopes). From what I have seen this approach is the fastest to execute in this language, but it has some minor draw backs with garbage collection. Since (prior to ES6) JavaScript does not have anything like a standard IO or module system a purely lexical approach tends to produce large functions or an object containing various large functions. Larger objects take longer for garbage collection to remove.
Using the memory allocation tool for Chrome from Paul Irish I can see that my purely lexical application is garbage collected just fine, but it takes longer to collect between code runs. If code runs too frequently against a large enough input memory consumption continues to rise until execution frequency slows. OOP code is likely have this problem because it is less likely to squeeze everything into a common scope, or collections that come together to share a common scope.
I tend to not worry about memory, though, in this language because its not something you have any control over. Typically its something that don't have any visibility on. Execution time, though, is very simple to profile, observe, and reduce.
-1
u/[deleted] Mar 09 '15
I disagree about call and apply though. I prefer to never use:
new
this (one exception)
Object.create
bind
call
apply
When I avoid this list my code tends to be smaller and faster to execute. You don't need OOP in this language, thanks to lexical scope, to achieve decomposable reuse and reference sharing.
The one exception for this is event handlers where it is commonly necessary to access the event target without access to an explicit reference.