JavaScript Part 2

"use strict;" at the top of your file means that if you just accidentally declare a variable without the "var" like y = 5, then usually it would become a global variable, but now it will throw an error.

  • closures can access variables outside
  • closures are good for info hiding (like private)
  • because you can have a closure (function) returning an object with methods/variables that can do stuff that affect the internal variables in that closure (but no one else has to see that).

2 ways to create new objects: 1) closure 2) adding objects to a constructor and calling it with new. without the "new" when calling the function or the "this" inside of the function, everything inside of the function becomes global variables!!! ahh!!!

Differential Inheritance: making new objects from objects (instead of types)

  • var deorio = Object.create(Professor);
  • that's not a reference to the Professor object; that's a new object made from the Professor object.

Javascript modifies the DOM not the HTML

The DOM is a recursively-defined tree

Event-driven callbacks are used to wait until my webpage is loaded, and then run my function you stupid browser.

window.onload = hello_func; // when the window loads, run my function

Function calls are on the stack objects live on the heap messages (event) are on the queue once a stack is empty, the queue runs and might put more stuff on the stack

Events & HTML

onkeyup onmounseover onclick onchange onload

  • node.js = a JS interpreter
  • development tools (chrome debugger)
  • jQuery = very popular JS library. like STL

JSLint = tries to warn you about all bad things in your code

google web toolkit = input is java, output is javascript

JS variables can have letters, numbers, underscore, & dollar signs