From a performance perspective, slice
is used twice in the code that follows. Using a shortcut will reduce both the length of the code to type, and the lookup process.
If you have slice in a local variable, there is single lookup needed when you access it:
In contrast, using Array.prototype.slice
typically translate to several "instructions":
- getVar "Array"
- getMember "prototype"
- getMember "slice"
From a minification perspective, tools like google compiler will also reduce the size code even further by renaming local variables (in this case slice
) to a single letter variable. That can not happen for global vars accessed outside scope (In that case Array.prototype.slice
).
From a functional perspective, Array.prototype.slice
is resolved dynamically, so it can change later. Assigning a local reference to the function object pointed to by Array.prototype.slice
at that point in time guarantees that no other code can change the function reference that you now hold yourself.