看板 Flash 關於我們 聯絡資訊
當eval()變得evil之後,好像有看過這兩種替代方案 getChildByName 跟 this[variable] 我今天在使用this[]的時候遇到了個問題,想請問一下有沒有人了解的, 因為我以為 this.path.reference is equivalent to this["path"]["reference"] and this["path"].reference and this.path["reference"] 可是我用 this["map.avatar.a"+i].visible=false; 卻遇到 ReferenceError: Error #1069: Property map.avatar.a1 not found on the1952 and there is no default value. at the1952/init() at the1952() 這個error,而使用 this.map.avatar["a"+i].visible=false; 卻完全正常,是否我的第一個式子有使用錯誤的地方? 感謝回答 <(_ _)> -- Ray的遊樂場:http://ray.myftp.org 歡迎光臨~ -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 76.189.150.40
Jerrynet:this[path][reference] ,不用加引號阿 05/07 07:31
Jerrynet:說錯了,要加引號~XD 05/07 07:37
Jerrynet:4339的推文不知道有沒有幫助XD 05/07 07:40
fatcats:this["map"]["avatar"]["a"+i].visible = false !? 05/07 07:46
fatcats:.應該是指到下一層或是屬性~可是你卻把它當成字串@@" 05/07 07:48
goodray:所以中間不能偷懶,它不會把"."判斷成分層的符號囉? 05/07 08:17
goodray:我還是一直把它當成eval()來用,壞習慣改不掉呀XD 05/07 08:18
Jedic:map.avatar["a"+i].visible=false;就可以了 05/07 08:45
Jedic:不必堅持寫上this,因為[]就可指向該物件之下的子物件 05/07 08:45
Jedic:所以this[]真正的重點是[]而不是this 05/07 08:47