Javascript call和apply

2016/1/10 posted in  JavaScript
function Animal(name,weight){
       this.name = name;
       this.weight = weight;
  }

  function Cat(){
       Animal.call(this,'cat','50');
       //Animal.apply(this,['cat','50']);

       this.say = function(){
           console.log("I am " + this.name+",my weight is " + this.weight);
       }
  }

  var cat = new Cat();
  cat.say();//I am cat,my weight is 50

执行Cat()时,先在其调用对象this的执行环境调用Animal(),相当于this.Animal()this.Animal()执行完以后,this上就产生了nameweight属性