在js中,当您将对象的属性键设置为其他对象时,键是什么?它是以字符串形式对对象的内存引用吗?还有别的吗?
例子:
// Let's create some apples.
const apple1 = { tastes: 'great' };
const apple2 = { tastes: 'so-so' };
// Let's create an orchard to hold our apples, with constant time look-up for any individual apple, so we're not using an array.
const orchard = {}
// And we add our first apple to the orchard. We want to keep track of some data.
orchard[apple1] = 1;
orchard[apple2] = 2;
此时,console.logging将显示orchard的键 [object Object]
. 控制台记录键的类型将告诉您[object]是一个字符串。但我可以有多个[对象]键,它们都是不同的。
暂无答案!
目前还没有任何答案,快来回答吧!