本文介绍了所有属性的Object.watch / __noSuchMethod__的垫片是否可用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

例如, localStorage ['somenewsetting'] = 123 会创建一个新设置。我想自动为这个属性定义一个getter / setter,这样我的加法代码也会为新设置执行。

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.

基本上我需要对象.watch ,但适用于所有属性。我发现的是,但Chrome无法使用。这种方法有没有可用垫片?或者是否有另一种方式来观看对象的所有属性?

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?

同样,我需要在Chrome上进行此操作。

Again, I need to make this work on Chrome.

推荐答案

不,至少,不是Chrome。无论如何, __ noSuchMethod __ 仅适用于函数。

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.

—有但被拒绝了。实施代理的请求不再成功:和Chromium团队。

— 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.

这篇关于所有属性的Object.watch / __noSuchMethod__的垫片是否可用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-27 16:23