@micosmo/core
Version:
Core Javascript language extensions
17 lines (13 loc) • 394 B
JavaScript
/*
* bind.js
* Alternate to f.bind(o) that returns the same bound function for the same input.
*/
;
module.exports = {
bind
};
const BoundFunctions = new WeakMap();
function bind(f, o) {
let t; const bindings = BoundFunctions.get(o) || (BoundFunctions.set(o, (t = new WeakMap())), t);
return bindings.get(f) || (bindings.set(f, (t = f.bind(o))), t);
}