ITeye博客

js的prototype原型设计模式

xushans · 2014-09-16 15:06 · js · Web前端 · prototype · Markdown

1.js对象的继承方式使用prototype原型模式。

2.js的方法可以分为以下三类: a.类方法 b.对象方法 c.原型方法


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();

3.obj1.func.call(obj)方法

是将obj看成obj1,调用func方法

评论(1)

  1. #1 楼 · conglianying · 2015-01-30 13:38

评论功能维护中,当前仅展示历史评论。