From: JavaEye.com
prototype provides a set of JavaScript object-oriented infrastructure. We can use it for object-oriented programming. The way to define object types is as follows:
var Person = Class.create();
Person.prototype = {
initialize : function(name, age) {
this.name = name;
this.age = age;
},
toString : function() {
document.writeln("[name]:" this.name "
" "[age]:" this.age);
}
}
First use Class.create() to create an object type, and then define the object type. Note that the initialize method is the constructor of Person. The complete HTML is as follows: