利用闭包实现缓存 var cacheTest = function(){var cache = {}, count=[];return {attachSearch: function(id){if(id in cache){return cache[id];}if(count.length > 2){delete cache[count.shift()];}cache[id] = id;count.push(id);return id;}}}();