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
上就产生了name
和weight
属性