Open matthewoates opened 8 years ago
The library currently accesses by function, and then by context. It's much more likely that the context will be garbage collected than a function.
eg:
function Foo { this._message = 'hi'; } Foo.prototype.bar = function () { console.log(this._message); }
var foo = new Foo(); bind(foo.bar, foo);
As you can see, with OOP, foo.bar, which is really Foo.prototype.bar, will never be garbage collected, however the foo instance will be.
foo.bar
Foo.prototype.bar
foo
By reversing the WeakMaps, it's very likely that the unbind function isn't needed anymore, making idempotent-bind a true drop-in replacement.
unbind
idempotent-bind
I can submit a PR if this change is welcome.
By reversing the WeakMaps
Ah, nice suggestion. (unbind is still needed for legacy enviroment.)
Yes! Welcome to PR :)
The library currently accesses by function, and then by context. It's much more likely that the context will be garbage collected than a function.
eg:
As you can see, with OOP,
foo.bar
, which is reallyFoo.prototype.bar
, will never be garbage collected, however thefoo
instance will be.By reversing the WeakMaps, it's very likely that the
unbind
function isn't needed anymore, makingidempotent-bind
a true drop-in replacement.I can submit a PR if this change is welcome.