javascript实现继承的方法

1:JS原型(prototype)实现继承

function Person(){}
   person.prototype.hello="hello";
   person.prototype.sayHello=function(){
      alert(this.hello);
}

function Child(){}
  child.prototype=new Person();
  child.prototypr.word="keeny";
  child.prototype.sayWord=(){
     alert(this.word);
}
 
 var c=new Child();
      c.sayHello;
      c.sayWord;

 

2:call()方法实现继承

     call的参数:第一个参数this值,第二个参数:参数直接传递给函数

      

function sun(){

}

 

3:apply()方法实现继承

   apply的参数:第一个参数是在其中运行函数的作用域,第二个参数是参数数组(可以是Array的实例,也可以是arguments对象),

4:对象冒充实现继承

5:

posted @ 2015-11-07 23:51  阿狸先生  阅读(95)  评论(0编辑  收藏  举报