On Dec 12, 2009, at 11:36 AM, Mike Wilson wrote:
Mark S. Miller wrote:
On Sat, Dec 12, 2009 at 10:36 AM, Mike Samuel <[email protected]>
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).
A String object is indexable (to get unit-length strings -- not
characters) with length as fencepost above the maximum index.
A string or String object wrapping it has immutable .length and [i]
for i < length properties, OTOH -- it is not frozen, but this raises
the question: is a frozen Array instance no longer array-like?
Prototype's isArray wants 'splice' in obj && 'join' in obj, but that
rules out many objects considered array-like, without monkey-patching.
We need a definition of array-like that matches common practice, if
there is a common practice. Then we can see (without prejudgment)
whether Strings satisfy it.
From Mike Samuel's posts and my own quick reading, I don't see too
much common practice. A more detailed survey of popular Ajax libraries
would be great -- I'm out of time right now, but I'll try later today
unless someone else does it first.
Anyhow, whatever is decided here I think primitive strings and
String wrappers should be handled the same way in this respect.
Right.
/be
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss