On 9/10/13 7:32 PM, Allen Wirfs-Brock wrote:
What do you think people are actually testing for when they do Array.isArray?
It varies, but some things I've seen people test for via "is array" methods:
1) Polymorphic methods that take an "array" or "something else". Just
looking at a random sampling of JS right now, I see a function that
takes as its first argument a URI or array of URIs, a function that
takes a colorspace or array of colorspaces, a function that takes a
callback or array of callbacks.
2) Functions (e.g. jQuery has some) that deep-clone object graphs and
wants to turn arrays into [] in the clone while turning other objects
into {}. A special case of this is implementations of structured
cloning, or indeed JSON.stringify.
3) Sanity checking of input parameters to functions. One could argue
that this is misguided, or that it saves debugging time; I've seen
people make both arguments.
-Boris
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss