4 ms·
The constructor check would unfortunately not work for cross-frame arrays. Each frame has its own global object, with its own Array constructor. So: var if
by zirak 5y ago
The constructor check would unfortunately not work for cross-frame arrays. Each frame has its own global object, with its own Array constructor. So:
var iframe = document.createElement('frame');
document.body.appendChild(iframe);
var value = iframe.contentWindow.Array();
value.constructor === Array // false
value instanceof Array // false
value instanceof iframe.contentWindow.Array // true
Stringifying the constructor works even for cross-frame values:
value.constructor.toString() === Array.toString() // true
These days though, `Array.isArray` is the right thing to do, available since roughly 2010.