我正在通过John Resig's snippets on advanced JavaScript。在#19他提到了一种方法来缓存函数的返回值。缓存具有多个参数的函数的返回值的最佳方式是什么?具有多个参数的函数的JavaScript缓存返回值
必须有比-ING字符串化的收到的参数和使用作为缓存对象的关键一个更好的方法:
function $$(selector, el) {
var cacheKey = JSON.stringify(arguments);
if ($$.cache[cacheKey]) return $$.cache[cacheKey];
return ($$.cache[cacheKey] = NodeListToArray((el || document).querySelectorAll(s)));
}
$$.cache = {};
那么,你有什么更多的给结果的身份? – Vengarioth 2013-03-11 06:16:39