Necessity of a syntax construct for bind

Lasse Reichstein reichsteinatwork at gmail.com
Tue Aug 30 12:59:21 PDT 2011


On Tue, Aug 30, 2011 at 6:42 PM, David Bruant <david.bruant at labri.fr> wrote:

>   Hi,
>
> A couple of people (including myself) have been working on trying to
> implement a Function.prototype.bind pure-JS implementation as close to the
> spec as possible.
> Despite the fact that this is impossible, all implementations relied on the
> built-in Function.prototype.call (or Function.prototype.apply).
>

I've had that problem in other cases too.

It's interesting that .call/.apply can't be protected from tampering without
freezing them.
If there was a function, say Function.callFunction, that allowed you to
write the equivalent of foo.call(bar, baz) as Function.callFunction(foo,
bar, baz), then you could store a copy of callFunction in a safe place and
not have to worry about Function.prototype.call being modified.

Any attempt I have tried of extracting the call functionality without
leaving a visible trace on the existing objects can be thwarted.
Most other functions can be extracted to local variables and called later on
the appropriate object (using .call) if you want to save an environment.


> A syntax construct allowing reliable binding without having me to go over
> one of the previous solutions would be welcome I think.
>

A reliable .call could probably also achieve the same.

/L
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20110830/c7f62e9e/attachment.html>


More information about the es-discuss mailing list