http://www.cnblogs.com/mindsbook/archive/2009/09/19/javascriptYouMustKnowPrototype.html
function myClass()
{
//此处相当于构造函数
this.ID = 1;
this.Name1 = this.Name;
this.showMessage();
}
myClass.prototype.Name = "johnson";
myClass.prototype.showMessage = function()
{
alert("ID: " + this.ID + ", Name: " + this.Name);
}
var obj1 = new myClass();
myClass.prototype.Name = "johnson2";
var obj2=new myClass();
alert(obj1.Name);
obj1.Name="tianlong";
alert(obj1.Name);
alert(obj2.Name);
function myClass()
{
//此处相当于构造函数
this.ID = 1;
this.Name1 = this.Name;
this.showMessage();
}
myClass.prototype.Name = "johnson";
myClass.prototype.showMessage = function()
{
alert("ID: " + this.ID + ", Name: " + this.Name);
}
var obj1 = new myClass();
myClass.prototype.Name = "johnson2";
var obj2=new myClass();
alert(obj1.Name);
obj1.Name="tianlong";
alert(obj1.Name);
alert(obj2.Name);