Catch access to undefined property in JavaScript [duplicate]

我与影子孤独终老i 提交于 2019-11-29 13:21:28

In ECMAScript's next version it should be quite easy, using Object.observe. Read more here: http://addyosmani.com/blog/a-few-new-things-coming-to-javascript/

Up, guys I think we need to vote for this feature on Google V8 issues list, here http://code.google.com/p/v8/issues/detail?id=264

It seems that there's no much attention to this very important feature :(

Daniel Vassallo

I would like to set a callback function to an Object that will be called whenever an undefined property in the Object is accessed or assigned to.

While this is not an exhaustive answer, keep in mind that assigning to undefined properties of an object is a key feature of the JavaScript language.

Also note that __noSuchMethod__ is a non-standard method, implemented by Mozilla's JavaScript engines. There is an open feature request for this to be implemented in Google Chrome's V8 engine, but as far as I know this is not supported in other browsers.

As of Feb 2014, It looks like this won't be supported any time soon.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!