azu / idempotent-bind

idempotent bind function library.
MIT License
15 stars 1 forks source link

Change WeakMap hirerarchy #2

Open matthewoates opened 8 years ago

matthewoates commented 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.

By reversing the WeakMaps, it's very likely that the unbind function isn't needed anymore, making idempotent-bind a true drop-in replacement.

I can submit a PR if this change is welcome.

azu commented 8 years ago

By reversing the WeakMaps

Ah, nice suggestion. (unbind is still needed for legacy enviroment.)

I can submit a PR if this change is welcome.

Yes! Welcome to PR :)