最近在读javascript忍者 感受下jquery作者 john Resig对于js的独到见解. 先上代码: function addMethod(object,name,fn){ var old = object[name]; //保存原有的函数,因为调用的时候可能不匹配传入参数的个数 object[name] = function(){ //创建一个新匿名函数作为新方法 if(fn.length == arguments.length){ //如果该匿名函数的形参个数和实参个数匹配,就调用…
函数重载 https://en.wikipedia.org/wiki/Function_overloading In some programming languages, function overloading or method overloading is the ability to create multiple methods of the same name with different implementations. Calls to an overloaded functi…
1.What's is 函数重载? );//Here is int 10 print("ten");//Here is string ten } 可以发现在C++中会根据参数的类型自动选择合适的函数执行,如果把上面的代码改造成Javascript代码如下: function print(i) { console.log("Here is num"+i); } function print(str) { console.log("Here is string…