显式键入变量会导致编译器认为内置类型的实例没有属性,而事实确实如此
我将 AS3 编译器错误 1119 的原因缩小到与此类似的代码:
var test_inst:Number = 2.953;
trace(test_inst);
trace(test_inst.constructor);
我收到错误“1119:通过静态类型 Number 的引用访问可能未定义的属性构造函数”。
现在,如果我省略变量的类型,我就不会收到该错误:
var test_inst = 2.953;
trace(test_inst);
trace(test_inst.constructor);
它会产生预期的输出:
2.953
[class Number]
那么这是怎么回事?我喜欢显式键入变量,那么除了不提供变量的类型之外,还有什么方法可以解决此错误吗?
I narrowed the causes of an AS3 compiler error 1119 down to code that looks similar to this:
var test_inst:Number = 2.953;
trace(test_inst);
trace(test_inst.constructor);
I get the error "1119: Access of possibly undefined property constructor through a reference with static type Number."
Now if I omit the variable's type, I don't get that error:
var test_inst = 2.953;
trace(test_inst);
trace(test_inst.constructor);
it produces the expected output:
2.953
[class Number]
So what's the deal? I like explicitly typing variables, so is there any way to solve this error other than not providing the variable's type?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
好吧,这有点难以解释……首先,它是如何工作的:
据我了解,这是因为属性
constructor
来自 ECMAScript-nature ActionScript 3。它是Object
实例的 ECMAScript 属性,通过 继承原型。从 ActionScript 3 的严格类型世界(也使用不同的继承机制)来看,此属性不可用。问候
后退2dos
ok, this is a little hard to explain ... first of all, here is how it works:
to my understanding, this comes from the fact, that the property
constructor
comes from the ECMAScript-nature of ActionScript 3. It is an ECMAScript property ofObject
instances and is inherited through prototypes. From the strictly typed world of ActionScript 3 (which also uses a different inheritance mechanism), this property is thus not available.greetz
back2dos
http://www.kirupa.com/forum/showpost。 php?p=1951137&postcount=214
包含您需要的所有信息:)
基本上,trace(test_inst["constructor"]) 可以工作。
http://www.kirupa.com/forum/showpost.php?p=1951137&postcount=214
that has all the info you need :)
basically, trace(test_inst["constructor"]) will work.
Object(someobject).constructor 将实现相同的效果——并且您不必处理编译器问题。
Object(someinst) === someclass 也可以。
DH
Object(someobject).constructor will achieve the same thing -- and you don't have to deal with compiler issues.
Object(someinst) === someclass works as well.
dh