renzaijiang
04-20-2009, 02:53 PM
<script>
classa=function(array)
{
return new classa.prototype.init(array);
}
classa.prototype={
init:function(array)
{
return this.setArray(array);
},
setArray : function(elems) {
this.length = 0;
Array.prototype.push.apply(this, elems);
return this;
}
}
classa.prototype.init.prototype=classa.prototype;
alert(classa([1,2,3])[0]);
alert(typeof(classa([1,2,3]));
</script>
this program was changed from source code of "jquery",
I don't know why classa([1,2,3]) can use like a array,
I don't how how keywords "new" works here, what "this" point step by step,
who can analysis this program for me ,any answer will be greatly appreciated.
classa=function(array)
{
return new classa.prototype.init(array);
}
classa.prototype={
init:function(array)
{
return this.setArray(array);
},
setArray : function(elems) {
this.length = 0;
Array.prototype.push.apply(this, elems);
return this;
}
}
classa.prototype.init.prototype=classa.prototype;
alert(classa([1,2,3])[0]);
alert(typeof(classa([1,2,3]));
</script>
this program was changed from source code of "jquery",
I don't know why classa([1,2,3]) can use like a array,
I don't how how keywords "new" works here, what "this" point step by step,
who can analysis this program for me ,any answer will be greatly appreciated.