JavaScript - the hard parts, Yehonatan Daniv

Get Started. It's Free
or sign up with your email address
Rocket clouds
JavaScript - the hard parts, Yehonatan Daniv by Mind Map: JavaScript - the hard parts, Yehonatan Daniv

1. general

1.1. namespace of all things defined

1.2. JS engine goes over names to resolve them

1.3. scope is created once we define it

1.3.1. e.g.

1.3.1.1. function

1.4. internally, engine creates a scope

1.4.1. allocates memory

1.5. when the function is called, the scope is initialized

1.6. nested scopes create scope chain

1.6.1. that's what the engine traverses when doing resolution

1.7. {} forms a scope in other languages, but not in JS

2. scopes & scope chains

2.1. Scope

2.1.1. Variable Object

2.1.1.1. VO

2.1.1.2. holds all *identifiers* declared in its context

2.1.2. For the global object it's window

2.1.3. there's a scope created when going over the definition, & there's an activation object when the function is invoked

2.1.3.1. Execution context

2.1.3.1.1. including parameters & context

2.2. Execution context

2.2.1. EC

2.2.2. VO + [[scope]] + the "this" value

2.2.3. Forms a closure

2.2.3.1. the execution context state is kept alive with the function

2.3. Flow

2.3.1. (see diagrams on slides)

2.4. Q&A

2.4.1. JS is as ugly as PHP, in the sense that there isn't much difference between local & global variables

2.4.1.1. It's very easy to override global variables when defining local variables

2.4.1.2. & vice versa, define global variables in local scopes by mistake

3. about

3.1. Yehonatan Daniv

3.1.1. Django & Client-side developer

3.2. tag line

3.2.1. how I learned to stop worrying & love JS

3.3. the talk is on the high-level, not about internals

3.3.1. which are dry & boring

4. The parts

4.1. this

4.1.1. a property of the EC

4.1.2. immutable

4.1.2.1. can't do:

4.1.2.1.1. this = ...

4.1.3. a reference to a JS object or to null

4.1.4. assigned by the caller when EC is created & entered

4.1.5. determined by the current form of call expression

4.1.5.1. engine checks what's left to the ()

4.1.5.1.1. reference type

4.1.5.1.2. else

4.1.5.2. examples

4.1.5.2.1. function foo() { alert(this); } foo();

4.1.5.2.2. foo.prototype.constructor();

4.1.5.2.3. dynamic binding:

4.1.5.3. in JS there are 9 types

4.1.5.3.1. ..

4.1.6. call expressions

4.1.6.1. examples

4.1.6.1.1. Untitled

4.1.6.2. ...

4.1.7. determination

4.1.7.1. rule of thumb

4.1.7.1.1. if a function is passed as a parameter

4.1.8. to change that

4.1.8.1. use bind

4.1.8.1.1. since ES5, it's in Function.prototype

4.1.8.1.2. using the trick

4.1.8.1.3. when we have a scope within scope

4.1.8.2. or

4.1.8.2.1. use global objects & always invoke methods of these global objects

4.2. prorotype & the __proto__ chain

4.2.1. The "OOP" in JS

4.2.2. history

4.2.2.1. JS was developed in about 2 weeks

4.2.2.2. was based on several paradigms

4.2.2.3. Java, Python, Lisp &c

4.2.3. OOP in JS

4.2.3.1. Instead of class -> Object

4.2.3.2. Instead of instance -> Object

4.2.3.3. Instead of super -> __proto__

4.2.3.3.1. implemented inly in some browsers

4.2.4. [[prototype]]

4.2.4.1. Every Object in JS has an internal, accessible & Immutable property - [[prototype]]

4.2.4.2. For Mozilla

4.2.4.2.1. __proto__

4.2.4.3. For others

4.2.4.3.1. ...

4.2.4.4. Eince ES5

4.2.4.4.1. Object.create

4.2.4.4.2. Object.getProtoytpeOf

4.2.5. functions have an attribute called prototype

4.2.6. Prototype chains

4.2.6.1. resolution chain is like scope

4.2.6.1.1. Object.property_name

4.2.7. ES3 syle

4.2.7.1. Untitled

4.2.7.2. enables us to create instances with given object as prototype

4.2.8. ES5 style

4.2.8.1. Untitled

4.2.8.2. Untitled

4.3. Q&A

4.3.1. ES5 (EcmaScript) supported in?

4.3.1.1. IE >= 9

4.3.1.2. FF >= 3.5

4.3.1.3. Chrome

4.3.1.4. Safari >= 5.1

4.3.2. JS will be killed next week by Google's Dart

5. slides

5.1. ...

5.1.1. document

5.1.1.1. reference to the DOM

5.1.1.2. contained in window

5.1.1.3. this isn't JS

5.1.1.3.1. it's a reference to the HTML DOM elements

5.2. types

5.2.1. window

5.2.1.1. the global scope (browser-based JS)

5.2.1.1.1. implemented as JS object

5.2.1.1.2. everything defined is there

5.2.2. local

5.2.2.1. either

5.2.2.1.1. function

5.2.2.1.2. with