Closed idoros closed 8 years ago
Thanks @idoros . Developers commonly want methods of a class autobound. Unfortunately, this proposal doesn't offer the appropriate semantics to support this, since at class definition time there's no instance to bind the method to.
Is there a particular use case that the unary bind operator doesn't address?
class Foo {
method() {}
}
let f = new Foo();
let boundMethod = ::f.method;
Could you not do a syntactical transform like the following?
class Foo {
::someMethod() {
// this will always be instance of Foo
}
}
var Foo = (function() {
var Foo = function() {
this.someMethod = this.someMethod.bind(this);
};
Foo.prototype.someMethod = function() {
// this will always be instance of Foo
};
return Foo;
})();
@nathggns, +1 That was what I was thinking...
Perhaps this could be added in the future, but closing for now.
it would be nice to have the same ability in classes, which would give automatic binding to class instance for selected methods: