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 50call()实现继承的原理我动,但是上面这段代码cat直接调用say()的话不应该是只执行Cat构造函数里的say方法吗?而Animal.call(this,'cat','50');这一行不应该没执行吗?难道是因为new一个cat实例的时候会把Cat函数先执行一遍么?求解
添加回答
举报
0/150
提交
取消