Using function.prototype.bind without breaking function.prototype.apply
On Wed, Sep 7, 2011 at 2:46 PM, Jake Verbaten <raynos2 at gmail.com> wrote:
var f = function() { return this; }
var g = f.bind(???);
g.apply({ "foo": "bar" }).foo // expect "bar"
Function.prototype.bind set's the thisArg to a certain value. Is there any way to leave it flexible to be overwritten using
.call
and.apply
later on?Is there any ES:Harmony/strawman proposal for this?
If there is not I propose using
undefined
to tell Function.prototype.bind to leave thisArg flexible.
We cannot use 'undefined' for this, as we already use f.bind(undefined) in order to ensure that f's "this" is useless, and therefore harmless.
Altogether, what you're asking for is similar to < strawman:soft_bind>, which, as you
see, can be implemented as a JS library. I suspect your weaker bind could use the same technique, and so needs no new support from the language.
On Wed, Sep 7, 2011 at 2:52 PM, Mark S. Miller <erights at google.com> wrote:
If there is not I propose using
undefined
to tell Function.prototype.bindto leave thisArg flexible.
We cannot use 'undefined' for this, as we already use f.bind(undefined) in order to ensure that f's "this" is useless, and therefore harmless.
Of course, that only works if f is constrained to be strict, which we ensure by other means.
var f = function() { return this; }
var g = f.bind(???);
g.apply({ "foo": "bar" }).foo // expect "bar"
Function.prototype.bind set's the thisArg to a certain value. Is there any way to leave it flexible to be overwritten using
.call
and.apply
later on?Is there any ES:Harmony/strawman proposal for this?
If there is not I propose using
undefined
to tell Function.prototype.bind to leave thisArg flexible.The use case would be using .bind to curry parameters without effecting this.