Skip to content

Instantly share code, notes, and snippets.

// http://jsperf.com/function-proto-bind/3
Function.prototype.bind = function(that){
var self = this,
args = arguments.length > 1 ? Array.slice(arguments, 1) : null,
F = function(){};
var bound = function(){
var context = that, length = arguments,length;
if (this instanceof bound){
F.prototype = self.prototype;
// A memoize function to store function results of heavy functions
// http://jsfiddle.net/arian/UQsEA/1/
(function(slice){
Function.prototype.memoize = function(hashFn, bind){
var cache = {}, self = bind ? this.bind(bind) : this, hashFn = hashFn || JSON.stringify;
return function(){
return ((key = hashFn(slice.call(arguments))) in cache)