显式键入变量会导致编译器认为内置类型的实例没有属性,而事实确实如此
我将 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 技术交流群。
发布评论
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
好吧,这有点难以解释……首先,它是如何工作的:
据我了解,这是因为属性
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