ADVANCED JS
with Kyle Simpson
Compilation
A conversation between Compiler and Scope manager
function foo(a) {
console.log( a + b );
}
b = 2;
foo( 2 ); // 4
Compiler: Hey Scope, do you have a function declaration for foo?
Scope manager: No.
Compiler: Please declare it.
Compiler: Hey Scope of foo, ever heard of formal parameter a?
Scope manager: No.
Compiler: Please declare it.
Formal declarations
Execution
A conversation between Engine and Scope
function foo(a) {
return a + b;
}
b = 2;
foo( 2 ); // 4
Compiler: Hey Scope, I have a LHS reference for b, ever heard of it?
Scope manager: No... but I'm helpful so I created it for you.
Compiler: Thanks I guess, please assign 2 to b.
Compiler: Hey Scope, I have a RHS reference for foo, ever heard of it?
Scope manager: Sure, it's a function, here you go.
Compiler: Thanks, execute it!
Compiler: Hey Scope of foo, I have a LHS ref. for a, ever heard of it?
Execution
A conversation between Engine and Scope
function foo(a) {
return a + b;
}
b = 2;
foo( 2 ); // 4
Scope manager: Well yes compiler declared it a millisecond ago. Voila!
Compiler: Merci beaucoup! Please assign 2 to a.
Compiler: Hey Scope of foo, I have a RHS ref, for a, ever heard of it?
Scope manager: Yup it's 2.
Compiler: Hey Scope of foo, I have a RHS ref. for b, ever heard of it?
Scope manager: Go fish.
Compiler: Hey upper Scope of foo, I have a RHS trf. for b, ever heard of it?
Scope manager: Sure, it's 2.
A
By Pontus Lundin
A
- 485