Hi Jakkir,
the first part of the code introduce a new namespace called "Class"
with one method called "Create".
This portion when called with:
var myClass=Class.create({
initialize:function(myVar){ ... },
myMethod1:function(myVar1){ ... },
myMethod2:function(myVar2){ ... },
...
});
var instance1=new myClass(myParameter); //will create a new instance
of myClass class.
instance1.myMethod1(myParameter1); //will launch the instance1
myMethod method
will create a new Class that will automatically launch the
myClass.initialize method: it's the constructor of the function.
But it also introduce inheritance, so you could create a new
"myNewClass" with the same method as "myClass". And you could also
overwrite "myClass" method in "myNewClass":
var myNewClass=Class.create(myClass,{
initialize:function($super,myNewVar){
...
//when need to call myClass constructor
$super(myNewVar);
....
},
myNewMethod1:function($super,myNewVar1){ ... },
MyNewLocalMethod:function(myLocalVar){ ... }
};
var newInstance1=new myNewClass(myNewParameter);
//this create a new instance of "myNewClass"
//internally, it will call the "myClass" constructor.
newInstance1.myNewMethod1(myParameter1);
//internally, it can call myMethod1 of "myClass".
newInstance1.MyNewLocalMethod(myLocalParameter1);
//method is only avalaible to the newInstance1 and not to instance1
The second part of the code is a extention that will added to you
instance so that you could extend properties of the instance created.
This a quite complicated portion of code wich need more than a thread
to be fully explained.
btw, I hope it demistify a little bit this code; if not, check:
for more information, first reed prototype API doc:
Class.create:
http://prototypejs.org/api/class/create
addMethods:
http://prototypejs.org/api/class/addMethods
you can also look at:
http://www.webreference.com/js/column79/index.html
http://ejohn.org/blog/simple-javascript-inheritance/#postcomment
--> also check comments for this post
http://www.sitepoint.com/blogs/2006/01/17/javascript-inheritance/
--
daivd