...

View Full Version : how does this program work?



renzaijiang
04-20-2009, 03: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.

A1ien51
04-25-2009, 03:43 PM
Do research in OO JavaScript. Plenty of material out there that will teach you how it works.

[1,2,3] is array notation. Any intro book to JavaScript will explain it.

Eric

danecookrulezz
04-25-2009, 07:51 PM
Here's a good intro
http://w3schools.com/js/js_obj_intro.asp



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum