funes
Remember everything, for better or for worse
Funes is a variadic memoizer: every time a function is called via funes, its output is cached. The next time the same expression is executed, funes returns the cached results instead of executing the function again.
It is a 'floating method', and operates on the function passed as this
- which plays nicely with ES7's bind operator (::
).
In ES7
import funes from 'funes'
const add = ( a, b ) => {
console.log( 'Adding!' )
return a + b
}
add( 1, 2 )
add( 1, 2 )
add::funes( 1, 2 )
add::funes( 1, 2 )
In an ES3+ browser
<script src="/lib/funes.es3.js"></script>
<script>
function add( a, b ){
console.log( 'Adding!' )
return a + b
}
add( 1, 2 )
add( 1, 2 )
funes.call( add, 1, 2 )
funes.call( add, 1, 2 )
</script>