代码示例:
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 //查看构造函数代码
测试验证:
完
网友评论