On the modified prototypes in JavaScript
I wrote a small function that can be used to retrieve links to the unmodified built-in methods (useful when you are running code in the environment where built-in objects’ prototypes were modified).
var getbuiltin = function(obj, fn) {
var iframe, func;
iframe = document.createElement('iframe');
iframe.style.display = 'none';
document.body.appendChild(iframe);
func = iframe.contentWindow[obj].prototype[fn];
document.body.removeChild(iframe);
return func;
};
/* Example: */
Array.prototype.push = function() {
this[this.length] = 'B';
};
var A = new Array();
A.push('A'); /* ['B'] */
var B = new Array();
B.push = getbuiltin('Array', 'push');
B.push('A'); /* ['A'] */
It works in Chrome, Safari and Firefox but not in Internet Explorer. There, you can’t access any JavaScript objects via frame’s window object. In other words, iframe.contentWindow.Array is undefined.
Puzzled.
Update: Thanks to Sanjar, aforementioned getbuiltin.js works in IE now.