[問題] this[]的問題

看板Flash作者 (RAY)時間17年前 (2008/05/07 07:22), 編輯推噓4(406)
留言10則, 4人參與, 最新討論串1/1
當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

05/07 07:31, , 1F
this[path][reference] ,不用加引號阿
05/07 07:31, 1F

05/07 07:37, , 2F
說錯了,要加引號~XD
05/07 07:37, 2F

05/07 07:40, , 3F
4339的推文不知道有沒有幫助XD
05/07 07:40, 3F

05/07 07:46, , 4F
this["map"]["avatar"]["a"+i].visible = false !?
05/07 07:46, 4F

05/07 07:48, , 5F
.應該是指到下一層或是屬性~可是你卻把它當成字串@@"
05/07 07:48, 5F

05/07 08:17, , 6F
所以中間不能偷懶,它不會把"."判斷成分層的符號囉?
05/07 08:17, 6F

05/07 08:18, , 7F
我還是一直把它當成eval()來用,壞習慣改不掉呀XD
05/07 08:18, 7F

05/07 08:45, , 8F
map.avatar["a"+i].visible=false;就可以了
05/07 08:45, 8F

05/07 08:45, , 9F
不必堅持寫上this,因為[]就可指向該物件之下的子物件
05/07 08:45, 9F

05/07 08:47, , 10F
所以this[]真正的重點是[]而不是this
05/07 08:47, 10F
文章代碼(AID): #188EX75y (Flash)