Necessity of a syntax construct for bind

David Bruant david.bruant at
Tue Aug 30 14:46:06 PDT 2011

Le 30/08/2011 21:59, Lasse Reichstein a écrit :
> On Tue, Aug 30, 2011 at 6:42 PM, David Bruant <david.bruant at
> <mailto:david.bruant at>> 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 (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, 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
> being modified.
True. I admit that i'm currently doing some JS static analysis and i
realize how much i prefer syntax over functions since syntax tends to be
easier to analyse statically. With syntax you never wonder "has the
semantic of this been overridden?" "if so, has the semantics changed?"
the latter question being in general undecidable i think.

> 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.
A reliable .call could be achieved by composing a reliable .bind and the
function call syntax.
However, due to the current impossibility to emulate .bind with .call
I'm doubtful that a reliable .bind (per ES5.1 is possible by
composition of a reliable .call and other things.
Based on harmony:spread [1], i think it could be possible to have a
reliable .apply based on a reliable .bind and function call syntax.

Consequently, I have the impression that syntax for a reliable .bind
would be a good fundamental brick to add to build the rest.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the es-discuss mailing list