超载[]在AS3运营商 [英] Overload [] operator in AS3

查看:163
本文介绍了超载[]在AS3运营商的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚写完我自己的收集类,我真的想使它可迭代的每个或简单的结构,或者只是访问元素的集合[关键]符号。

I just finished writing my own collecion class, and i'd really like to make it iterable with the for each or the simple for construct, or just to access elements with the collection[key] notation.

我已经写了 getElementAt(指数):MyOwnElement 的功能,但使用它,是不是性感与使用方brachets,甚至都不让我开始在迭代..

I've written a getElementAt(index):MyOwnElement function, but using it, is not as sexy as using the square brachets, don't even let me start on iterating..

有什么办法?

推荐答案

您应该看一看的 mx.utils.Proxy - 从子类集合类(并将其设置为动态)可能会给你访问一些你想要的功能(或至少东西是足够接近。)

You should take a look at mx.utils.Proxy -- subclassing your collection class from that (and setting it as dynamic) might give you access to some of the functionality you want (or at least something that's close enough.)

例如,下面是从 nextValue()方法的文档的摘录:

For example, here's an excerpt from the documentation of the nextValue() method:

允许的代理枚举   对象的属性由索引号   检索属性值。但是,你   无法枚举的属性   自己代理类。 此功能   支持实施的...在的   的for each..in 循环对象上   检索所需的值。

"Allows enumeration of the proxied object's properties by index number to retrieve property values. However, you cannot enumerate the properties of the Proxy class themselves. This function supports implementing for...in and for each..in loops on the object to retrieve the desired values."

这篇关于超载[]在AS3运营商的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆