isArray((function(){ return arguments; })(1,2))
  and
isArray(document.getElementsByTagName('*'))
both return true in cajoled JS. That is the problem. They are not
truly arrays and should not inherit the properties of Array.prototype.

On Jun 18, 5:20 pm, Mike Samuel <[email protected]> wrote:
> 2010/6/18 Michael Ficarra <[email protected]>:
>
>
>
>
>
> > I am having difficulty distinguishing between arrays and array-like
> > objects in cajoled code. It seems that caja does not provide a
> > facility to differentiate an arguments object from an array (since it
> > does not allow access to the `callee` property for legitimate security
> > reasons) or a NodeList from an array, since it only mixes in the
> > required `item` method to a standard array. Running the following code
> > both cajoled and uncajoled should give more insight into the problem I
> > am facing:
>
> > var collection = document.getElementsByTagName('*');
> > console.log('collection', collection.constructor !== Array, 'item' in
> > collection);
> > var args = (function(){ return arguments; })(0,1);
> > console.log('arguments', args.constructor !== Array, 'callee' in
> > args);
> > console.log('array', [].constructor === Array);
>
> > There should be no falsey values logged to the console. This
> > difference in how caja treats array-like objects shouldn't cause any
> > functional problems other than the loss of the ability to distinguish
> > arrays from array-like objects.
>
> > tl;dr How does one distinguish between arrays and array-like objects
> > in cajoled code?
>
> function isArray(value) {
>   return 'object' == typeof value && value !== null
>       && '[object Array]' === Object.prototype.toString.call(value);
>
> }
>
> ?

Reply via email to