function Base(){}Base.prototype = {x:10, y:[]}function A(){}A.prototype = new Base();var a = new A();a.y.push("first");a.x = 9;console.log(a.x);console.log(a.y);function B(){}B.prototype = new Base();var b = new B();b.y.push("second");b.x = 11;console.log(a.x);console.log(a.y);
允许结果如下:
9["first"]9["first", "second"]
注意这里,原型中有基本数据类型和对象类型(比如数组)的时候行为不一致,需要理解引用类型的概念。