Also in other languages you can usually bypass scope via reflection if you really need to. Js closures though, good luck as far as u know. Usually gotta copy the entire closure by text then edit the raw string then eval if you need to hook something or edit a private variable
That "combination" being a function and and a reference to the scope chain that represents the lexical scope. If two closures are defined in the same scope, the reference to their scope chain will be the same.
Because closure and scope isn't the same in javascript either. A closure can have access to three scopes. It's own scope, an outer functions scope, and global variables.
You can also take a function as an argument (or from a reference in an outer scope), and apply it inside the current function’s scope, which is how classes are “extended.”
152
u/[deleted] May 28 '19
Closure is a concept I see lots of beginners struggle with. You can massively speed up dev time once you grasp how it works in JS.