作者goodray (RAY)
看板Flash
标题[问题] this[]的问题
时间Wed May 7 07:22:45 2008
当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
1F:推 Jerrynet:this[path][reference] ,不用加引号阿 05/07 07:31
2F:推 Jerrynet:说错了,要加引号~XD 05/07 07:37
3F:推 Jerrynet:4339的推文不知道有没有帮助XD 05/07 07:40
4F:推 fatcats:this["map"]["avatar"]["a"+i].visible = false !? 05/07 07:46
5F:→ fatcats:.应该是指到下一层或是属性~可是你却把它当成字串@@" 05/07 07:48
6F:→ goodray:所以中间不能偷懒,它不会把"."判断成分层的符号罗? 05/07 08:17
7F:→ goodray:我还是一直把它当成eval()来用,坏习惯改不掉呀XD 05/07 08:18
8F:→ Jedic:map.avatar["a"+i].visible=false;就可以了 05/07 08:45
9F:→ Jedic:不必坚持写上this,因为[]就可指向该物件之下的子物件 05/07 08:45
10F:→ Jedic:所以this[]真正的重点是[]而不是this 05/07 08:47