var a = {"x": 1};
var b = a;
console.log(b.x);
a.x = 2;
console.log(b.x);
a = {"x":3};
console.log(b.x);
a.x = 4;
console.log(b.x);
为什么输出的是
1
2
2
2
Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
对象的赋值属于引用类型,
除了基本类型, 其他对象都是引用方式赋值包括数组和函数