引用文献:js忍者秘籍
var store = {//demo:函数存储----存储一组独立的函数
nextId:1,
cache:{},
add:function(fn){
if(!fn.id){
fn.id = store.nextId++;
return !!(store.cache[fn.id] = fn);
}
}
}
function say(content){
console.log(content);
}
assert(store.add(say),"store function : say");
assert(store.add(say),"store function : say");
consoloe.log("say.id:",say.id);
store.cache.valueOf("say")[1]("Hello world");
output:
say.id: 1
Hello world