General question: When a default Javascript prototype like Array has been modified, hacked, changed and twisted to the point of being unusable, is there any
You could just copy Array methods from the iframe:
Array.prototype.slice = function() {
return "trololol";
};
var a = document.createElement("iframe");
a.src = "about:blank";
document.body.appendChild(a);
var prototype = a.contentWindow.Array.prototype;
var fn = ["toString", "toLocaleString", "join", "pop", "push", "concat", "reverse", "shift", "unshift", "slice", "splice", "sort", "filter", "forEach", "some", "every", "map", "indexOf", "lastIndexOf", "reduce", "reduceRight"];
for (var i = 0; i < fn.length; ++i) {
var methodName = fn[i];
var method = prototype[methodName];
if (method) {
Array.prototype[methodName] = method;
}
}
document.body.removeChild(a);
Here's the jsfiddle that works in chrome and IE9, don't have time to figure out IE7-8. http://jsfiddle.net/jMUur/1/
To check if an object is an Array without relying on references:
function isArray( obj ) {
return {}.toString.call( obj ) === "[object Array]";
}