On Fri, Dec 11, 2009 at 12:08 PM, Mike Wilson <mike...@hotmail.com> wrote: > Mark S. Miller wrote: > > If we're looking for a convention that is > * does not admit any legacy ES3R non-array non-host objects (to prevent > false positives)
No native ES objects? > * does easily allow ES5 programmers to define new array-like non-array > objects > * takes bounded-by-constant time (i.e., no iteration) *What* takes bounded-by-constant time? The object's existence would not take any time. > * is a reasonably compatible compromise with the existing notions of > array-like in legacy libraries as represented by previous examples in this > thread Can you please clarify what the problem area is a little more? > then I suggest: > function isArrayLike(obj) { > var len; > return !!(obj && > typeof obj === 'object' && > 'length' in obj && > !({}).propertyIsEnumerable.call(obj, 'length') && > (len = obj.length) >>> 0 === len); > } > Is looks like "array like" is defined as an an object where "length" is non-enumerable and numeric. What about [[Get]], [[HasProperty]] for numeric property names? And why must the - length - property be an *own* property? Why could length not be a getter in the prototype chain? Indeed many Mozilla DOM collections work this way: javascript: var cn = document.links; alert([cn.length, ({}).hasOwnProperty.call( cn, "length")]); Mozilla elerts "80, false" Garrett _______________________________________________ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss