What does the object[foo] term mean?

后端 未结 3 1042
孤独总比滥情好
孤独总比滥情好 2021-01-21 02:34

I\'m confused what the object[foo] term is referring to. Any hints? I know that bar[\'unique_prop\'] and bar.unique_prop refers to

3条回答
  •  轮回少年
    2021-01-21 03:16

    object[foo] = 'value';
    

    attempts to use an object as a member name, this causes a .toString() call so;

    'value' is assigned to object["[object Object]"], when you attempt to read alert(object[bar]); the same toString() occurs as bar is also an object, so you reference object["[object Object]"] once again and get back 'value'.

提交回复
热议问题