Created
June 10, 2014 03:53
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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