`
ztianlong
  • 浏览: 65279 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

javascript prototype

 
阅读更多
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);
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics