限制 ActionScript 3 中条目大小的地图/字典
在Java中,这可以通过 LinkedHashMap 通过删除最旧的条目/最早访问的条目。 ActionScript 3 中是否有等效的类?
谢谢。
In Java, this can be done with LinkedHashMap by removing eldest entry/oldest accessed entry. Any equivalent class in ActionScript 3?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不,不幸的是没有。您可以轻松实现一个,如果我要实现它,我会扩展 代理对象 它会给你相当大的灵活性。
更新:
此更新是为了澄清OP评论中的问题。评论是“这将是一个扩展 Proxy 的新类,而不是 Dictionary/etc?”
是的,您想要扩展 Proxy,这样做的原因是它允许您重写几个魔术方法来完成你的目标。特别是在您的情况下,您可以覆盖
setProperty(name:*, value:*):void
。每次在类上设置属性时都会调用此方法(由您提供设置实现),以便您可以计算在给定时间设置的值的数量。如果您扩展对象或字典,则您无权访问它,并且有知道何时设置新属性的方法。如果您扩展对象,则需要依赖接口来实现您的目标,要求用户通过方法调用设置属性。
代理实现仍然允许您设置如下属性:
方法实现(扩展对象)将如下所示:
No, unfortunately not. You could easily implement one, if I were going to implement it I would extend the Proxy object It'll give you a fair bit of flexibility.
UPDATE:
This update is to clarify on the question in the comment by the OP. Comment was "It will be a new class extends Proxy and not Dictionary/etc?"
Yes, you would want to extend Proxy, the reason for this is that it allows you to override several magic methods to accomplish your goal. Particularly in your case, you can override
setProperty(name:*, value:*):void
. This method will be called every time a property is set on your class (its up to you to supply the set implementation) so you can count the number of values that are set at a given time. If you extend Object or dictionary, you do not have access to this, and have know way of knowing when a new property is set.If you extended object instead, you would need to rely on an interface to to acheive your goal, requiring user to set properties through method calls.
A Proxy implementation would allow you still set properties like this:
A method implementation (extending Object) would look like this: