first_page the funky knowledge base
personal notes from way, _way_ back and maybe today

JavaScript: “The Miller Device”; Identifying an Array; Douglas Crockford

The JavaScript language currently does not provide a good way to distinguish between objects and arrays. The typeof operator is broken: It identifies arrays as objects. Comparing a value's constructor property doesn't work because arrays created in a different frame will have a different constructor. There are do-it-yourself tests for arrayness, but they are complicated and unreliable.

Mark Miller of The Google, by closely reading the ECMAScript standard, has discovered a simpler, more reliable test.

Object.prototype.toString.apply(value) === '[object Array]'

[http://blog.360.yahoo.com/blog-TBPekxc1dLNy5DOloPfzVvFIVOWMB0li?p=916]

mod date: 2008-10-18T01:18:03.000Z