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.