Javascript 有类似 Ruby 的 method_missing 功能吗? [英] Does Javascript have something like Ruby's method_missing feature?

查看:24
本文介绍了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天全站免登陆