文章出處
文章列表
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){}) //只與參數個數有關
文章列表
全站熱搜