标签:func cti return var ons turn fun span class
var searchBox = (function() { var cache = {},count = 0, index = []; return function(key, value) { if (cache[key]) { return value; } cache[key] = value; count += 1; index.push(key) if (count > 2) { index.shift() //如果超出了限制,将最早的key删除 } return cache; } })(); console.log(searchBox("name", "xxax")) // {name: "xxax"} console.log(searchBox("name", "xxax")) // xxax console.log(searchBox("name", "xxax")) // xxax console.log(searchBox("age", 23)) // {name: "xxax", age:23} console.log(searchBox("age", 23)) // 23
标签:func cti return var ons turn fun span class
原文地址:https://www.cnblogs.com/yuyedaocao/p/12049022.html