所以我想扩展字典类。 到目前为止,一切正常,除了在我的一些需要引用字典内容的方法中,我进行了如下调用:
this[ key ]
它不喜欢那样。 它只是告诉我没有财产“钥匙”。 有没有办法访问此类中的数据?
另外,我使用整数作为密钥。
编辑:我发现当您扩展 Array 时会发生相同的行为。
var myArray : Array = new Array();
trace( myArray[ 0 ] );
var myArrayExtender : ArrayExtender = new ArrayExtender();
trace( myArrayExtender[ 0 ] );
在这种情况下,myArray 返回“未定义”并且 myArrayExtender 抛出错误 1069。ArrayExtender 是一个空类,它扩展 Array 并在构造函数中调用 super()。
So I want to extend the dictionary class. Everything works so far except that in some of my methods that need to reference the dictionary's content I make a call like:
this[ key ]
It doesn't like that. It just tells me that there's no property 'key'. Is there a way to way to access the data within this class?
Also, I'm using an integer for the key.
Edit: I've found that the same behavior happens when you extend Array.
var myArray : Array = new Array();
trace( myArray[ 0 ] );
var myArrayExtender : ArrayExtender = new ArrayExtender();
trace( myArrayExtender[ 0 ] );
Where in this case, myArray returns "undefined" and myArrayExtender throws error 1069. ArrayExtender is an empty class that extends Array and calls super() in the constructor.
发布评论
评论(1)
从你所说的来看,我很确定你没有将
ArrayExtender
声明为dynamic
在 ECMAscript 中,数组访问和属性访问在语义上是等效的...如果您在 密封类,因为它们不允许在运行时添加属性...
对于
字典
也是如此...greetz
后退2dos
from what you say, i am quite sure you did not declare
ArrayExtender
asdynamic
in ECMAscript array access and property access are semantically equivalent ... #1069 happens, if you access an undefined property, on a sealed class, because thes do not allow adding properties at runtime ...
same thing for the
Dictionary
...greetz
back2dos