Javascript是否具有Ruby的method_missing功能?

Javascript是否具有Ruby的method_missing功能?

问题描述:

在Ruby中,我认为你可以调用一个尚未定义的方法,然后捕获被调用方法的名称,并在运行时处理这个方法。

In Ruby I think you can call a method that hasn't been defined and yet capture the name of the method called and do processing of this method at runtime.

Javascript可以做同样的事情吗?

Can Javascript do the same kind of thing ?

您正在解释的ruby功能称为method_missing http://rubylearning.com/satishtalim/ruby_method_missing.htm

The ruby feature that you are explaining is called "method_missing" http://rubylearning.com/satishtalim/ruby_method_missing.htm.

这是一个全新的功能,仅在某些浏览器中出现,例如Firefox(在蜘蛛猴Javascript引擎中)。在SpiderMonkey中,它被称为__noSuchMethod__ https://developer.mozilla.org/ en / JavaScript / Reference / Global_Objects / Object / NoSuchMethod

It's a brand new feature that is present only in some browsers like Firefox (in the spider monkey Javascript engine). In SpiderMonkey it's called "__noSuchMethod__" https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Object/NoSuchMethod

请阅读Yehuda Katz撰写的这篇文章 http://yehudakatz.com/2008/08/18/method_missing-in-javascript/ 了解即将实施的更多细节。

Please read this article from Yehuda Katz http://yehudakatz.com/2008/08/18/method_missing-in-javascript/ for more details about the upcoming implementation.