First mode: Factory mode
var lev=function () {return " home of the script ";};
function Parent () {var child = new Object (); Child.name= " script "; Child.age= "4"; Child.lev=lev; return child; };
var x = Parent ();
alert (x.name);
Alert (X.lev ());
Second mode: constructor mode
var lev=function () {return " home of the script ";};
function Parent () {this.name= " script "; This.age= "30"; This.lev=lev; };
var x =new Parent ();
alert (x.name);
Alert (X.lev ());
Third mode: Prototype mode
var lev=function () {return " home of the script ";};
function Parent () {};
Parent.prototype.name= " Bruce Lee ";
Parent.prototype.age= "30";
Parent.prototype.lev=lev;
var x =new Parent ();
alert (x.name);
Alert (X.lev ());
Fourth mode: Mixed constructors, prototype mode (recommended)
function Parent () {this.name= " script "; this.age=4; };
Parent.prototype.lev=function () {return this.name;};
var x =new Parent ();
Alert (X.lev ());
Fifth mode: Dynamic prototyping mode
function Parent () {this.name= " script "; this.age=4; if (typeof parent._lev== "undefined") {
Parent.prototype.lev=function () {return this.name;} Parent._lev=true; }
};
var x =new Parent ();
Alert (X.lev ());
Several ways of JS object-oriented