David-Sarah Hopwood wrote:
> Mark S. Miller wrote:
>> function isArrayLike(obj) {
>>   var len;
>>   return !!(obj &&
>>             typeof obj === 'object' &&
>>             'length' in obj &&
>>             !({}).propertyIsEnumerable.call(obj, 'length') &&
>>             (len = obj.length) >>> 0 === len);
>> }
>>
>> Since getting 'length' may have side effects, this is written a bit weird so
>> that this get only happens after earlier tests pass.
> 
> If you want to avoid side effects:
> 
> function isArrayLike(obj) {
>   if (!obj || typeof obj !== 'object') return false;
>   var desc = Object.getPropertyDescriptor(obj, 'length');

getOwnPropertyDescriptor, I meant.

>   if (desc) {
>     var len = desc.value;
>     return !desc.enumerable && (len === undefined || len >>> 0 === len);
>   }
> }

-- 
David-Sarah Hopwood  ⚥  http://davidsarah.livejournal.com

Attachment: signature.asc
Description: OpenPGP digital signature

_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to