var once = (function(){ var memo = {},i = 0; return function(fn){ for(var k in memo){ if(memo[k].func == fn || memo[k].func.toString() == fn.toString()){ return memo[k].result; } } var result = fn.apply(this,Array.prototype.slice.apply(arguments,1)); memo[i++] = {func:fn,result:result}; return result; } })();
参考:https://segmentfault.com/q/1010000000520596