3 ms·
Douglas Crockford has said that he considers Lisp and Javascript to be similar languages. For that reason, I think it would help those confused/frustrated with
by jessedhillon 16y ago
Douglas Crockford has said that he considers Lisp and Javascript to be similar languages. For that reason, I think it would help those confused/frustrated with 'this' to read the chapters of SICP that relate to the environment model, and to 'eval' and 'apply':
Environment model of evaluation, http://mitpress.mit.edu/sicp/full-text/book/book-Z-H-21.html#%_sec_3.2 http://mitpress.mit.edu/sicp/full-text/book/book-Z-H-21.html...
Metacircular evaluator, http://mitpress.mit.edu/sicp/full-text/book/book-Z-H-26.html#%_sec_4.1 http://mitpress.mit.edu/sicp/full-text/book/book-Z-H-26.html...
The environment model is crucially helpful. Applying it to Javascript, think of bound functions (ones which are methods on instantiated objects) implicitly having a 'let this = instance' statement prepended to their bodies.
- jhuni 16y agoJavaScript is incredibly different from Lisp, at least syntactically. Here are some legal JavaScript expressions: ++x+x++ x >> 6 > y >> 6 5 % 2 / 5 * 5 + 1
- sid0 16y agoIt's good that Crockford meant semantically, then.
- munificent 16y ago> Applying it to Javascript, think of bound functions (ones which are methods on instantiated objects) implicitly having a 'let this = instance' statement prepended to their bodies. Except that Javascript under normal circumstances doesn't have bound functions. A method (a function property on some object) is unbound unless you go out of your way to bind it. So it only conceptually has that "let this = ..." prepended to it within the duration of an invocation that's using property access to get the function. In other words, JS doesn't include "this" in a function's closure, which is where a lot of the confusion comes from.