array like objects

Mike Wilson mikewse at hotmail.com
Sat Dec 12 11:36:32 PST 2009


Mark S. Miller wrote:



On Sat, Dec 12, 2009 at 10:36 AM, Mike Samuel <mikesamuel at gmail.com> wrote:


On the String defect, we could repair that with
   && ({}).toString.call(obj) !== '[object String]'
Cons:
  An extra function call in the likely case
  Strings are arguable array-like
Pros:
  Strings are inconsistently indexable : (new String('foo'))[0] is
undefined on IE 6 

 
Yes, this test would work. Before incorporating it, we should discuss
whether String wrapper objects should indeed be considered array-like. My
inclination is that they should not. Opinions? 

I don't think strings should trigger array-like, and this seems to be the
position held by most JS libraries (see f ex dojo.isArrayLike). The normal
use of these methods is to identify things like Arguments and NodeLists, ie
sequences of distinct objects/values, not character sequences (text).
Anyhow, whatever is decided here I think primitive strings and String
wrappers should be handled the same way in this respect.
 
Best regards
Mike
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20091212/1f1e848c/attachment-0001.html>


More information about the es-discuss mailing list