問題緣起
var exists={
1 : true
}
console.log(exists[{toString:()=>1}])
//true
自己的分析
難道做了隱式轉(zhuǎn)換宙址?(后來發(fā)現(xiàn)這根本不叫隱式轉(zhuǎn)換)
查到解釋
Property names must be strings. This means that non-string objects cannot be used as keys in the object. Any non-string object, including a number, is typecasted into a string via the toString method.
拓展思考
這么說數(shù)組的下標(biāo)舶得,其實(shí)也是屬性名熟妓,只是數(shù)組是js內(nèi)置的特殊數(shù)據(jù)結(jié)構(gòu)耐薯,所以它在chrome上表現(xiàn)成這個(gè)樣子兴枯。其實(shí)本質(zhì)就是一個(gè)多了length屬性微王,__proto__
指向Array.prototype的對(duì)象
比如:[1,2,3][1]===[1,2,3]['1']等價(jià)的判呕,1是number,會(huì)執(zhí)行toString方法轉(zhuǎn)換成'1'