js.弄清对象方法-类方法-原型方法
2020-08-05 本文已影响0人
Andy计算机专业
![](https://img.haomeiwen.com/i9428859/abb04cdd5f671e51.png)
代码示例:
function People(name)
{
this.lsx=name;
//对象方法
this.fdx=function(){
alert("My name is "+this.lsx);
}
}
//类方法
People.fl=function(){
alert("I can run");
}
//原型方法
People.prototype.fyx=function(){
alert("我的名字是"+this.lsx);
}
//测试
var p1=new People("Windking");
p1.fdx();
p1.fyx();
People.fl();
People.prototype.fyx()
//查看
Object.keys(People) //查看类方法
People.prototype //原型方法+类方法
p1 //查看对象方法+原型方法+类方法
People //查看构造函数代码
测试验证:
![](https://img.haomeiwen.com/i9428859/25fb06fc797502dc.png)
完