On 12 August 2015 at 02:56, Isiah Meadows <[email protected]> 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
[email protected]
https://mail.mozilla.org/listinfo/es-discuss