var cat ={};
cat.mouse = function(){var b="1111"};
var dog =
cat;
console.log(dog);
console.log(dog.mouse);
dog.mouse =
function(){var b="2222"};
dog.hat="b";
console.log(cat)
Object {mouse: function}
- hat: "b"
- mouse: function (){var b="2222"}
- __proto__: Object
function (){var
b="1111"}
Object {mouse: function, hat: "b"}
- hat: "b"
- mouse: function (){var b="2222"}
- __proto__: Object
对象赋值后,指向了同一个对象,及时改变的是第二个对象,第一个对象也跟着变。
时间: 2024-12-08 16:18:51