Javascript是否具有Ruby的method_missing功能? [英] Does Javascript have something like Ruby's method_missing feature?

查看:160
本文介绍了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.

这篇关于Javascript是否具有Ruby的method_missing功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆