美文网首页
js.弄清对象方法-类方法-原型方法

js.弄清对象方法-类方法-原型方法

作者: Andy计算机专业 | 来源:发表于2020-08-05 10:07 被阅读0次

代码示例:
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              //查看构造函数代码

测试验证:

相关文章

网友评论

      本文标题:js.弄清对象方法-类方法-原型方法

      本文链接:https://www.haomeiwen.com/subject/dpdnrktx.html