Skip to content

Instantly share code, notes, and snippets.

@Williammer
Created June 10, 2014 03:53
Show Gist options
  • Select an option

  • Save Williammer/1eb0653838d05b9e9526 to your computer and use it in GitHub Desktop.

Select an option

Save Williammer/1eb0653838d05b9e9526 to your computer and use it in GitHub Desktop.
javaScript.objCacheFn.js - use object to cache unique and related functions, with the key-value structure similar to array in PHP.
var store = {
nextId: 1,
cache: {},
add: function (fn) {
if (!fn.id) {
fn.id = this.nextId;
this.nextId += 1;
return !!(this.cache[fn.id] = fn);
}
}
}
var testFn = function (xxx) {
console.log('just for test' + xxx);
}
store.add(testFn);
console.dir(store.cache);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment