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

相关文章:

  • 2021-10-27
  • 2022-01-11
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-03-09
  • 2021-09-07
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案