var a = { }; var b = { key: "a" }; var c = { key: "c" }; a[b] = "123" a[c] = "456" console.log(a[b]);
输出的结果是 456
因为
对象的键值会转换为字符串 a[b] == a["[object Object]"]
可以打印一下看看结果
console.log(b.toString() == "[object Object]");
和这个结果
console.log(a["[object Object]"]);