我正在尝试 Douglas Crokford 视频中的这个示例,据我所知,更改新对象不应更改旧对象。
var oldObject = {
firstMethod:function(){
console.log("This is first method");
},
secondMethod:function(){
console.log("This is second method");
}
}
var newObject = Object(oldObject);
newObject.thirdMethod=function(){
console.log("thirdMethod");
}
newObject.firstMethod=function(){
console.log("I am not first method");
}
newObject.firstMethod();
oldObject.firstMethod();
输出:
I am not first method
I am not first method
但我期待,
I am not first method
This is first method
请让我知道我错在哪里。