Array2 VS Array

Thoughts About How to Subclass The JavaScript Array Object

Before you start to test my codes, you should read Dean Edwards's post about the same topic since he started this first by creating a extra WINDOW obejct (IFRAME) to host different JavaScript objects.

The Hack

Instead of using IFRAME, I use window.createPopup for IE to fix some issues which Dean Edwards talked about

Now I only test with and found these compatible browsers

Now test it


var Array2 = function(){};

Array2.prototype = new Array;

Array2.prototype.bar = function(){
		alert("this.bar() --> This.Length=" + this.length );
	}

function test(){

	alert('call Array2');
	var a = new Array2();
	a.push(1);
	a.push(2);
	a.bar();

	alert('call Array');
	var b = new Array();
	b.push(1);
	b.push(2);
	b.bar();


	}catch(err){

		alert( err.message || err );
	}

}
Thanks, Hedger Wang