Created
October 31, 2012 16:03
-
-
Save lynxerzhang/3987902 to your computer and use it in GitHub Desktop.
关于as3中in操作符的使用问题
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
in 用于在诸如Dictionary Object 对象中尝试返回指定键是否存 | |
var d = new Dictionary(); | |
var s = new Sprite(); | |
d[s] = true; | |
trace(s in d); // true | |
但目前假设d对象是自定义类, 并且覆盖了Object的toString()方法, | |
同时在toString()方法中, 正巧有访问为空的自定义属性,而s又正好不是d | |
对象的键, 那么此时居然会触发TypeError空对象错误, 解决方法是使用[] | |
操作符, 或者使用try...catch...预先处理下try {s in d}。 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
in 用于在诸如Dictionary Object 对象中尝试返回指定键是否存 | |
var d = new Dictionary(); | |
var s = new Sprite(); | |
d[s] = true; | |
trace(s in d); // true | |
但目前假设d对象是自定义类, 并且覆盖了Object的toString()方法, | |
同时在toString()方法中, 正巧有访问为空的自定义属性,而s又正好不是d | |
对象的键, 那么此时居然会触发TypeError空对象错误, 也许是内部调用了toString() | |
方法, 解决方法是使用[]操作符, 或者使用try...catch...预先处理下try {s in d}。 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment