function addMethod(object,name,fn){ var old=object[name]; object[name]=function(){ if(fn.length==arguments.length) return fn.apply(this,arguments); else if(typeof old=='function') return old.apply(this,arguments); }; }
使用: var gc={}; addMethod(gc,'whatever',function(){}) addMethod(gc,'whatever',function(a){}) addMethod(gc,'whatever',function(a,b){}) //只与参数个数有关