function ClassA(sColor) {this.color = sColor;this.sayColor = function () {alert(this.color);};}function ClassB(sColor, sName) {this.newMethod = ClassA;this.newMethod(sColor);delete this.newMethod;this.name = sName;this.sayName = function () {alert(this.name);};}var objA = new ClassA("blue");var objB = new ClassB("red", "John");objA.sayColor(); //輸出 "blue"objB.sayColor(); //輸出 "red"objB.sayName(); //這個代碼 塊function ClassB(sColor, sName) {this.newMethod = ClassA;this.newMethod(sColor);delete this.newMethod;<<<<<<=====中 delete this.newMethod;已經把指向classA的引用刪掉了,為什么objB.sayColor();還能起作用
添加回答
舉報
0/150
提交
取消