Last active
December 18, 2015 02:29
-
-
Save vinioliveira/5711239 to your computer and use it in GitHub Desktop.
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
| function cache_store(callback,key,value){} | |
| function cache_retrieve(callback,key) {} | |
| function slow_function(callback,input){} | |
| function memorize(callback, slow_function) { | |
| var self = this, result; | |
| self.result = cache_retrieve(callback,slow_function); | |
| if(!self.result) | |
| { | |
| self.result = function(cb, input){ | |
| value = slow_function.call(self, cb, input); | |
| cache_store(self.callback,slow_function, value); | |
| return value; | |
| }; | |
| } | |
| return self.result; | |
| } | |
| fast_function = memorise(slow_fucntion); |
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
| function cache_store(callback,key,value){} | |
| function cache_retrieve(callback,key) {} | |
| function slow_function(callback,input){} | |
| function memorize(slow_function) { | |
| var self = this, result; | |
| cache_retrieve(function(value){ | |
| self.result = value; | |
| },slow_function); | |
| if(!result) | |
| { | |
| self.result = function(callback, input){ | |
| value = slow_function.call(self, callback, input); | |
| cache_store(function(){},slow_function, value); | |
| return value; | |
| }; | |
| } | |
| return self.result; | |
| } | |
| fast_function = memorise(slow_fucntion); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment