function People(name){
this.name=name;
//对象方法
this.Introduce=function(){
console.log("My name is "+this.name);
}
}
//类方法
People.Run=function(){
console.log("I can run");
}
//原型方法
People.prototype.IntroduceChinese=function(){
console.log("我的名字是"+this.name);
}
//测试
var p1=new People("大宝");
p1.Introduce();
People.Run();
p1.IntroduceChinese();
最近正在学习js的原型,在网上搜索的例子,请问下对象方法与类方法以及原型方法的区别是什么呢?在实际应用过程中应该怎么选择呢?
茅侃侃
FFIVE
互换的青春
随时随地看视频慕课网APP
相关分类