限制 ActionScript 3 中条目大小的地图/字典

发布于 2024-10-16 21:52:36 字数 221 浏览 2 评论 0原文

在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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

皇甫轩 2024-10-23 21:52:36

不,不幸的是没有。您可以轻松实现一个,如果我要实现它,我会扩展 代理对象 它会给你相当大的灵活性。

更新:

此更新是为了澄清OP评论中的问题。评论是“这将是一个扩展 Proxy 的新类,而不是 Dictionary/etc?”

是的,您想要扩展 Proxy,这样做的原因是它允许您重写几个魔术方法来完成你的目标。特别是在您的情况下,您可以覆盖 setProperty(name:*, value:*):void。每次在类上设置属性时都会调用此方法(由您提供设置实现),以便您可以计算在给定时间设置的值的数量。如果您扩展对象或字典,则您无权访问它,并且有知道何时设置新属性的方法。

如果您扩展对象,则需要依赖接口来实现您的目标,要求用户通过方法调用设置属性。

代理实现仍然允许您设置如下属性:

myObj.foo = 'bar';
myObj["foo"] = 'bar';

方法实现(扩展对象)将如下所示:

myObject.setVal("name", "val");

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:

myObj.foo = 'bar';
myObj["foo"] = 'bar';

A method implementation (extending Object) would look like this:

myObject.setVal("name", "val");
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文