Named Arrow Functions
Salvador de la Puente González
salva at unoyunodiez.com
Wed Aug 12 14:46:05 UTC 2015
AFAIK, this wont work because what clearTimeout() is actually expecting is
the id returned by setTimeout().
El 12/8/2015 16:00, "Nick Krempel" <ndkrempel at google.com> escribió:
> On 12 August 2015 at 02:56, Isiah Meadows <isiahmeadows at gmail.com> wrote:
>
>> ```js
>>
>> let p = new Promise((resolve, reject) =>
>> setTimeout((x => () => x(x))(handler => {
>> onNotNeeded(() => clearTimeout(handler));
>>
>> // `return` is to take advantage of TCO
>> return doSomethingAsync(err => {
>> if (err != null) return reject(err)
>> else return resolve();
>> });
>> }));
>> ```
>>
> This doesn't work as the function passed to clearTimeout does not === the
> function passed to setTimeout.
>
> In fact, they're not even behaviorally equal as the function passed to
> setTimeout is expecting no parameters and the function passed to
> clearTimeout is expecting one parameter - i.e. this is not even correct in
> lambda calculus.
>
> A lambda-calculus-correct version could be:
>
> ```
> setTimeout((x=>(y=>()=>x(y(y)))(y=>()=>x(y(y))))(handler => {...}));
> ```
>
> But this would still suffer from the object identity problem mentioned
> above. A final JS-correct version could be:
>
> ```
> setTimeout((x => {const y = () => x(y); return y;})(handler => {...}));
> ```
>
> Nick
>
>
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20150812/e163b368/attachment.html>
More information about the es-discuss
mailing list