ruby的method_missing魔法在JavaScript中是否有类似等价物?答案是SpiderMonkey的__noSuchMethod__ 方法。演示如下(请firebug大神出马):
总结:
[list]
[*]ruby:method_missing
[*]JavaScript(SpiderMonkey): __noSuchMethod__ (有可能会成为ECMAScript 3.1标准)
[*]smalltalk:doesNotUnderstand
[*]Objective-C:forward::
[/list]
参考:[url]http://yehudakatz.com/2008/08/18/method_missing-in-javascript/[/url]
var obj = {};
obj.__noSuchMethod__ = function(/*String*/methodName,/*Array*/arrArguments){
console.log(methodName, arrArguments);
}
obj.test(1,2);
// 打印出:"test", [1, 2]
总结:
[list]
[*]ruby:method_missing
[*]JavaScript(SpiderMonkey): __noSuchMethod__ (有可能会成为ECMAScript 3.1标准)
[*]smalltalk:doesNotUnderstand
[*]Objective-C:forward::
[/list]
参考:[url]http://yehudakatz.com/2008/08/18/method_missing-in-javascript/[/url]