Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
"use strict";
var cache = new WeakMap();
Object.prototype.boundTo = function(fct){
var obj = this;
var objMap = cache.get(fct);
if(objMap === undefined){
objMap = new WeakMap();
cache.set(fct, objMap);
var bound = objMap.get(obj);
if(bound === undefined){
bound = fct.bind(obj);
objMap.set(obj, bound);
return bound;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment