Js 的prototype

javascript的方法可以分为三类:

a 类方法

b 对象方法

c 原型方法

javascript中的每个对象都有prototype属性,Javascript中对象的prototype属性的解释是:返回对象类型原型的引用。

function People(name)
{
  this.name=name;
  //对象方法
  this.Introduce=function(){
    alert("My name is "+this.name);
  }
}
//类方法
People.Run=function(){
  alert("I can run");
}
//原型方法
People.prototype.IntroduceChinese=function(){
  alert("我的名字是"+this.name);
}

 

//测试

var p1=new People("Windking");

p1.Introduce();

People.Run();

p1.IntroduceChinese();

 

原文链接

http://www.cnblogs.com/yjf512/archive/2011/06/03/2071914.html

 

posted on 2014-10-29 12:36  苏上话  阅读(168)  评论(0)    收藏  举报