Another trick to allow Array subclasses
Written by on November 24th, 2006 in Ajax News.
Dean Edwards talked about his hack that got us the ability to subclass the Array object in JavaScript.
Hedger Wang has a new hack that uses window.createPopup instead of an iframe to for IE to fix some issues.
If you take a view source to see what is in there, you get the gem:
if(!window.createPopup){return};
var fs = function(){
/==/
var Array2 = parent.Array2 ;
var p1 = Array.prototype ;
var p2 = Array2.prototype;
for(i in p2 ){
p1[i] = p2[i];
};
parent.Array2 = Array;
parent.document.title = ‘Array2 is ready’;/*debug msg*/
/==/
};
document.title = ‘Prepare Array2′;/*debug msg*/
fs = (fs + ”).split(’/==/’)[1];
window.createPopup().document.body.innerHTML = ‘<img src="null" onerror="’ + fs + ‘" />’;
})();
var Array2 = function(){};
Array2.prototype = new Array;
Array2.prototype.bar = function(){
alert(”this.bar() –> This.Length=” + this.length );
}
Source: Ajaxian
Original Article: http://ajaxian.com/archives/another-trick-to-allow-array-subclasses