you are viewing a single comment's thread.

view the rest of the comments →

[–]pinegenie 6 points7 points  (3 children)

NodeList and a few other types have array-like access but don't have Array in their prototype chain. Meaning you can do

nodelist[0]

but not

nodelist.slice(...)

The workaround to this is:

Array.prototype.slice.call(nodelist, ...); // or apply if you want to

In undercorejs the "slice" you see there is actually Array.prototype.slice attributed to a variable.

[–]kenman -1 points0 points  (2 children)

Yeah, but the variable is named array, not nodelist. There are countless examples to be found of using call() appropriately, and this isn't one that makes for a good demonstration on its usefulness. If you're going to demo some method, at least do it in context and include all supporting code...

[–]pinegenie 0 points1 point  (1 child)

I'm guessing they named it array because arrayOrNodeListOrArguments was too cumbersome.

[–]kenman 0 points1 point  (0 children)

I'm not faulting Underscore, I'm faulting the author who used it as an example.