是否有针对所有属性的 Object.watch / __noSuchMethod__ 的垫片可用?

发布于 2024-11-16 15:20:18 字数 534 浏览 6 评论 0原文

我想通过每次获取/存储设置时执行一些代码来扩展 localStorage 。我可以为 localStorage 的所有现有属性定义一个 getter/setter,但问题在于新的设置。

例如,localStorage['somenewsetting'] = 123 创建一个新设置。我想自动为此属性定义一个 getter/setter,以便我的附加代码也针对新设置执行。

基本上我需要 Object.watch,但对于所有属性。我发现的是 __noSuchMethod__,但它在 Chrome 上不可用。有适用于此方法的垫片吗?或者是否有另一种方法来观察对象的所有属性?

再次强调,我需要在 Chrome 上实现此功能。

I would like to extend localStorage by executing some code each time a setting is fetched/stored. I could define a getter/setter for all existing properties of localStorage, but the problem lies in new settings.

For example, localStorage['somenewsetting'] = 123 creates a new setting. I would like to automatically define a getter/setter for this property so that my addition code is also executed for new settings.

Basically I need Object.watch, but for all properties. What I found was __noSuchMethod__, but it is not available on Chrome. Is there any shim available for this method? Or is there another way of watching all properties of an object?

Again, I need to make this work on Chrome.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

零度℉ 2024-11-23 15:20:18

不,至少对于 Chrome 来说不是。无论如何, __noSuchMethod__ 仅适用于函数。

代理 支持正在讨论以用于下一个ECMAScript (Harmony) 版本,甚至 已经实现蜘蛛猴。恐怕在那之前你就不走运了。

— 有在 V8 中实现 __noSuchMethod__ 的请求但被拒绝了。实施代理的请求并未更加成功:633 已合并为重复项,而 Chromium 团队不太关心实现代理支持

Nope, at least, not for Chrome. __noSuchMethod__ only works for functions, anyway.

Proxy support is under discussion for the next version of ECMAScript (Harmony), and even already implemented in SpiderMonkey. Until then, you're out of luck, I'm afraid.

— there was a request to implement __noSuchMethod__ in V8 but it was refused. Requests to implement Proxy haven't been any more successful: 633 was merged as duplicate, and the Chromium team doesn't care much about implementing Proxy support.

南渊 2024-11-23 15:20:18

是的,我也想要那个。很多很多其他人也是如此。不会发生的。曾经。 Chrome (V8) 在 JS API 方面遵循 webkit。 __noSuchMethod__ 是 Mozilla 创建的非标准事件,已被 ECMAScript (JavaScript) 正式拒绝。

换句话说,它永远不会存在:'(

(或者即使存在,也将在经过多次争论后出现,而且不会很快出现)

Yeah, I want that too. So do many, many other people. Isn't going to happen. Ever. Chrome (V8) follows webkit in terms of its JS API. __noSuchMethod__ is a non-standard event created by Mozilla and has been officially rejected from ECMAScript (JavaScript).

In other words, it will never exist :'(

(or if it does, it will be after much arguing and it won't be any time soon)

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