article

REVIEW - learning to love javascript

 

  1. ] about this[63:26] video presentation by Alex Russell
    1. ] given by Alex Russell, Alex works @google chrome team, & represents google @ tc39, standards committee for js
  2. ] contents presentation - learning to love javascript(js) - 
    1. ] where are we now
    2. ] how to get a different future for js
    3. ] how these things relate to one another
  3. ] js is a functional, dynamic language
    1. ] supports closures, like schema, 
  4. ] js history  
    1. ] 1995 netscape 2 - mocha / livescript
    2. ] 1996 
    3. ] 1997 js standard
    4. ] 1999 ecmascript v3 - pretty much the same version that we use today,
    5. ] js has gone everywhere, every browser
    6. ] competing on performance  
    7. ] todays runtimes and performance are vastly different than in the past, even the recent past 
    8. ] the web is the platform
  5. ] js is misunderstood
    1. ] no type system, no type testing (unless you add it in)
    2. ] there are 'types' ( number, object, array,  )
    3. ] js runs top to bottom - no thread system no way to branch off, browsers have implemented WA with Browser setTimeOut, setInterval() but its not a language feature ] interpreter and runtime both read it and interpret it in the same way, top to bottom
    4. ] everything is an object
  6. ] almost everything is 'muteable' 
    1. ] we can change our objects
    2. ] there are some exemptions, very small, narrow,  but can be powerful
  7. ] closure 
    1. ] the way to do private variables ( data hiding) in js
    2. ] js inverts the relationship between 'classes' and 'functions
    3. ] FUNCTIONAL OOP = behaviour that carries data VS 
    4. ] CLASSICAL OOP = data that carries behaviour
    5. 12:00] privates, - encloses its lexical scope, holds on vars, way of passing var around, 
    6. ] first class functions - participants in the Obj model system, participants in the storage system
    7. ] fundamental concept that underpins a lot of the patterns we build upon
    8. ] work together with other 'functonal' ideas -
    9. ] ex ARRAY prototype - has ] filter,]map,]reduce, ] foreach methods 
    10. ] so instead of external iterator you have an internal iterator - 
    11. ] creating a stack of stuff you would like to do (in terms of behaviour) instead of ...
    12. ] passing the same data structures around and around 
    13. ] pass in arguements to functions, 
    14. ] express your programs intent in the form of nested functions that are going to unwind to some result ...
    15. ] NOT linear functions that is going to have the same data structures passed into them over and over again ..
  8. ] defining a functional language
    1. ] see below 
  9. ] the only way to create a 'scope' is to invoke a function
    1. ] defining  
    2. ] scopes are really smart, they hold onto the variables that have been defined above them
    3. ] tradittional lang constructs - for, while, switch, ...  - dont create scopes
    4. ] behaviour that has hidden storage to pass data around, maintain state
    5. ]
  10. ] prototypes
    1. ] 1 link chain delegation to root object
  11. ] first class Functions
    1. ] behaviour that carries data VERSUS data that carries behaviour (tradditional OOP programming)
  12. [15:00] everything being an object
    1. ]
  13. [] all objects act like a map
    1. ] so if you want a map, take an object
    2. ] arrays do the same thing
    3. ] NOT a linear bag of memory, you access with an index, like in many other languages
    4. ] arrays are just objects
    5. ] length property is the only magical part about it - affects visibility of property's
  14. [17:30] not many core concepts, if you understand them, you will understand js
    1. / muteable objects - properties of an object can be added or removed at run time
    2. / closures - behaviour that carries data 
    3. / everything being an object - 
    4. / objects act like maps - 
  15. [19:00] closures - the other side of classes 
    1. classes are state with behaviour - example 
    2. closures are functions with state  - example
    3. - you dont create classes that are "state with behaviour", you create "behavioiur" that holds on to the state that it needs, you pass that behaviour around
  16. [22:22] prototypal inheritance 
    1. ] example (es5) Object.Create() 
    2. ] will look at the object that you create ...
    3. ] incredibly powerful - you can create brand new 'behaviour' at runtime, compose things on the next line that didnt exist before
    4. ] can change the behaviour of other objects in the system based on what they are delegating to ..
  17. [26:00] understanding 'this.' is really important!
    1. x]- because you dont have classes that wire up the inheiritance heirarchy, 
    2. ] because were always delegating at run time,  
      1. ] every "." operator, does the dynamic lookup on the local object , example this.name
      2. ] looks at its delegate, which looks at its delegate, ...
    3. ] this ===  "whatever "scope i'm" in, execute the "next lookup" against the "local" object"
    4. ] the this keyword in any function isnt pointing at some fixed object , ADD CODE EXAMPLE #  
    5. ] it is "permiscous", it points at whatever object my function is being called through, call their own data
    6. ] nice little syntactic out, whenever i lookup a property, which happens to be a function, and i call it, 
      1. the dot operator, for method calls says, 
      2. dont just return it, evaluate it directly, 
      3. use the .call property of the function thats returned and call it within the scope of 
    7. ] in order to 'wire it up'  
    8. - use the .call property of the function object thats returned and call it in the scope of the object thats on the lh side , see CODE EXAMPLE #
    9. - i know its a little bit may tricky -
    10. - in order to wire this behaviour up correctly so that it sort of does what you expect in other languages 
    11. - we rely on the function being first class
    12. - i can "call" "any function" in the scope of "any other object" assign and call it through the object
    13. - use the this keyw
    14. -ability to create 
  18. [28:10] we can recreate things like 'classes' 
    1. ] mix ins for instance level composition
  19. [31:50] extending the native js objects 
    1. ] mutability + prototypes - extend the stuff that is deffered to in the system
  20. []  

  1. what makes something a functional programming language?
    1. ] can it have 'side effects'?
    2. ] does it support 'macro languages' or hygenic macros
    3. instead of p
  2. ] it has closures, first class functions 
ex CODE == 
obj.method() === obj["method"].call(obj);
Function
- PROPS arity, caller, constructor, length, name 
- METHS apply, bind, call, isGenerator, toSource, toString
[call ]
- method of the function object, 
[apply ]
- method of the function object, applies to arrary
this
EXAMPLE - 1 - this js
var person = new Person("john","doe");
console.log(this.first, this.last); 
// returns john doe
EXAMPLE - 2 - this jquery 
button.click
this refers to button 
EXAMPLE - 3 
this is not assigned a value until an object invokes the function where this is defined. Let’s call the function where this is defined the “this Function.”
 Even though it appears this refers to the object where it is defined, it is not until an object invokes the this Function that this is actually assigned a value. And the value it is assigned is based exclusively on the object that invokes the this Function. 
this has the value of the invoking object in most circumstances. 
EXAMPLE The use of this in the global scope
 
window.showFullName()
VS
person.showFullName()
] When this is most misunderstood and becomes tricky
The this keyword is most misunderstood when ] we borrow a method that uses this, ] when we assign a method that uses this to a variable, ] when a function that uses this is passed as a callback function, and ] when this is used inside a closure—an inner function. We will look at each scenario and the solutions for maintaining the proper value of this in each example.
Details Photos Edit more

Details

ID: 1702

NAME: REVIEW-learning-to-love-javascript

DESCRIPTION: whats NEW ...] a talk by Alex Russell @ Google i/o 2011

AUTHOR: article.author/s

EDITOR: article.editor/s

PUBLISHER: article.publisher/s

STATUS: Write

PRIORITY: 0

OWNER ID: 75

Content Photos Edit more

photos

page_photo

actions

Email Email-Owner SMS and