0.0.7 • Published 10 years ago

cache-fn v0.0.7

Weekly downloads
5
License
MIT
Repository
github
Last release
10 years ago

cacheFn

Make your calculate heavy function more effective!

usage

npm install cache-fn

example

var cacheFn = require('cache-fn');
function yourFunc(args1 [, args2 ...]){
    //your code with heavy calculation here
}

var yourCacheFunc = cacheFn(yourFunc);
//as long as yourFunc is a calculate heavy function
//yourCacheFunc is a more effective function that does the same thing yourFunc does for you
//and it remembers the calling of yourFunc and it's return value
//next time, when you call it again with the same arguments, it will directly return the value

use thisArg argument

var cacheFn = require('cache-fn');
var obj = {
    foo : 'xxx',
    fn1 : function(args1 [, args2 ...]){
        //complex calculation code here
    }
};
var cacheFn1 = cacheFn(obj.fn1, obj);  //pass obj as the second argument 
//cacheFn1 is now a cached function
//when you call cacheFn1(args1 [, args2...]), obj.fn1 will be executed with this point to obj
0.0.7

10 years ago

0.0.6

10 years ago

0.0.5

10 years ago

0.0.4

10 years ago

0.0.3

10 years ago

0.0.2

10 years ago

0.0.1

10 years ago