marijnh / Eloquent-JavaScript

The sources for the Eloquent JavaScript book
https://eloquentjavascript.net
3.01k stars 793 forks source link

Error in the sandbox, not present in other environments (ex #15.2) #481

Closed bitwkit closed 5 years ago

bitwkit commented 5 years ago

The solution I made for the exercise 15.2 is working fine in JSFiddle, Codepen and as a local html file in browser (Chrome 65.0.3325.181), but produses the following error when being run in the sandbox: "TypeError: Cannot read property 'style' of undefined (line 26)"

Code: exercise 15.2

marijnh commented 5 years ago

Ah, you're using an obscure feature in setTimeout that isn't supported by the overridden version in the sandbox. Attached patch should fix that.

marijnh commented 5 years ago

(Also, you can just access charNode from inside the function you pass to setTimeout, so you don't need to pass it as an extra argument through setTimeout)

bitwkit commented 5 years ago

(Also, you can just access charNode from inside the function you pass to setTimeout, so you don't need to pass it as an extra argument through setTimeout) Is this because of clojure? ...and if this is an "obscure" feature of setTimeout, does it mean it is not recommended to use?

marijnh commented 5 years ago

Is this because of clojure?

Yes (though Clojure is a Lisp dialect, and the feature is called closure)

...and if this is an "obscure" feature of setTimeout, does it mean it is not recommended to use?

It's standard, and it should work fine—I just wasn't aware of it when I wrote the placeholder.

bitwkit commented 5 years ago

Thanks a lot! And thank you very much for the book!