javascript继承时的一个问题

prototype中属性是对象时,继承时可能出现的问题
Shape = function(){}
Shape.prototype = {
    area: [1,2,3]

}

var Rectange = function(){
    this.area.push(4);

}

Rectange.prototype = new Shape();

var Square = function(){
  

}
Square.prototype = new Shape();

console.log(new Rectange().area.length);

console.log(new Square().area.length);

你可能感兴趣的:(JavaScript,prototype)