function memoizeFunction(func) { var cache = {}; return function() { var key = arguments[0]; if (cache[key]) { return cache[key]; } else { var val = func.apply(this, arguments); cache[key] = val; return val; } }; }; function add(x,y){ var result = 0; this.x = x; this.y = y; result = this.x + this.y console.log(result); }; memoizeFunction(add(19,3)); //22 memoizeFunction(add(19,3)); //还是22, 但从缓存中读取,速度快