Necessity of a syntax construct for bind
es-discuss at michael.ficarra.me
Wed Aug 31 10:56:26 PDT 2011
This is my first reply on es-discuss, so my apologies if I've done something
incorrectly and this doesn't get properly routed.
David and Lasse, I'd like to direct you to
https://github.com/kriskowal/es5-shim and, in particular, pull request #43:
In that series of commits, I removed all runtime dependence on the
environment and bootstrapped Function.prototype.bind while relying only on
the existence of Function.prototype.call at definition time and with no
dependencies at runtime. This allows me to call any function using
`call(functionName, thisArg, argument0, argument1, ...)`. I also used that
to bootsrap a similar `apply` function. The general idea behind
bootstrapping a bind method was to make a sub-par `call` and `apply`
implementation that relied on `Function.prototype.call.call`, but replacing
them after defining bind by using our new bind method similarly to how you
suggested. It'd probably be easier to just read the code, though, than have
me continue trying to explain it.
---------- Forwarded message ----------
> From: David Bruant <david.bruant at labri.fr>
> To: Lasse Reichstein <reichsteinatwork at gmail.com>
> Date: Wed, 31 Aug 2011 11:28:54 +0200
> Subject: Re: Necessity of a syntax construct for bind
> Le 31/08/2011 10:52, Lasse Reichstein a écrit :
> On Tue, Aug 30, 2011 at 11:46 PM, David Bruant <david.bruant at labri.fr>wrote:
>> Le 30/08/2011 21:59, Lasse Reichstein a écrit :
>> 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.
> True. The Bind operation is the currying of the Call operation.
> Ah, that got me thinking. I can do
> var CallFunction = Function.prototype.call.bind(Function.prototype.call);
> since bind does give a different way to set the this-object for a call.
> This can be done once, before anybody gets to mangle the builtins, and can
> be stored for afterwards. Excellent!
> Of course, it requires a native Function.prototype.bind, but that's
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the es-discuss