getify / You-Dont-Know-JS

A book series on JavaScript. @YDKJS on twitter.
Other
179.5k stars 33.5k forks source link

Contextual error, possibly, in Books 2 Ch. 1 #1453

Closed WordsofDefiance closed 5 years ago

WordsofDefiance commented 5 years ago

I'm reading through the first chapter of the book about this and object prototypes.

We said earlier that this is not an author-time binding but a runtime binding.

Where did you guys say this earlier? I definitely missed it if you did. in fact, we don't get a working definition of this until the end of the chapter.

This seems like an oversight, but apologies if this is intentional!

lalosh commented 5 years ago

Where did you guys say this earlier? scope and closure book, appendix A

https://github.com/getify/You-Dont-Know-JS/blob/master/scope%20%26%20closures/apA.md

At the end of the appendix you find what you want:

The key contrast: lexical scope is write-time, whereas dynamic scope (and this!) are runtime. Lexical scope cares where a function was declared, but dynamic scope cares where a function was called from.

Finally: this cares how a function was called, which shows how closely related the this mechanism is to the idea of dynamic scoping. To dig more into this, read the title "this & Object Prototypes".

getify commented 5 years ago

(clearing out issues for second edition work)