开发者

Some question of object property name in Actionscript3

A.as

package
{
    public class A
    {
        public static var someObject:Object = {
            (B.SOME_CONST): { value: 10 }
        };
    }
}

B.as

pac开发者_StackOverflow社区kage
{
    public class B
    {
        public static const SOME_CONST:String = "someStringConst";
    }
}

And this is test code.

var obj:Object = A.someObject;
trace(obj.hasOwnProperty(B.SOME_CONST));
trace(obj.hasOwnProperty("someStringConst"));
trace(obj.hasOwnProperty("SOME_CONST"));

I expected that result will be true, true, false but real result is false, false, true. Why?


For some reason, changing the line to (B["SOME_CONST"]): {value:10} works, although the parenthesis will still need to be there. I have not been able to find a reason as to why this is the case though. It is definitely a bug though.

At first I thought it was a problem with the parser stumbling over the dot or something, but after some more tests it seems not to be the case:

package
{
    public class A
    {
        public var someObject:Object = {
            (C.b["SOME_CONST"]): { value: 10 }
        };
    }
}
package {
    public class B
    {
        public static const SOME_CONST:String = "someStringConst";
    }
}
package {
    public class C
    {
        public static var b:Class = B;
    }
}

If it had been a problem with the parser, it would resolve to b["SOME_CONST"] and thus an runtime exception. However, the code works as expected without problems.

So this is really interesting.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜