js 对象方法、类方法、原型方法区别


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(); //原型方法也需要通过实例化对象去调用

posted @ 2019-03-16 20:23  一路向北√  阅读(925)  评论(0编辑  收藏  举报

web应用开发&研究 -

业精于勤而荒于嬉。

工作,使我快乐。


Font Awesome | Respond.js | Bootstrap中文网