javascript prototype

司宏伯
2023-12-01
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);
 类似资料:

相关阅读

相关文章

相关问答