Doug Crockford: Advanced JavaScript

Douglas Crockford: "Advanced JavaScript" (1 of 3)
Douglas Crockford: "Advanced JavaScript" (2 of 3)
Douglas Crockford: "Advanced JavaScript" (3 of 3)

Classical vs. prototypal inheritance. JS is about the only example of the latter. It does this with a "secret link" over which names can be resolved.

Augmentation affects objects created prior to the augmentation.

psuedo classical inheritance - looks classical but it isn't: introduce a new operator; constructor fuctions, new operator, prototype member of functions.

if you omit the new keyword, the global variable is clobbered by the constructor (passed in as this). A serious design error with JavaScript.

all function objects get a prototype member object containing a constructor

use the object function to produce new objects that have same state and behavior as existing objects. then augment them by assigning new members.

some functions that don't use 'this 'are "priveledged" and can't be reused. They get secret info from closures.

doug likes parasitic inheritance

be shallow and avoid deep hierarchies. js pays a high performance cost for deep hierarchies.

debugging tools:
  1. IE: ms script debugger (office 2003, visual studio /express)
  2. mozilla: venkman (doesn't work that well in firefox; good on moz), firebug (good but not complete)
  3. safari: drasara
Cool a new tool (and it's free!). He likes watches, call stack, and locals. Has a bug - can't set a breakpoint on first line of a function! Create a stupid first line to workaround.

Venkman: really needs Mozilla. Comes with Mozilla already. tools|web development|turn on debugger.

You can use a 'debugger' statement for programmatic breakpoint. You can wrap a breakpoint around it. helpful for onload bugs.

Video 3 - performance

Hoare's dictum: premature optimization is the root of all evil.

first priority correctness, then optimize.
look for algorithmic solution
common subexpression removal -
loop invariant removal

variables are very cheap - use to cache values.
string concat with + allocates memory (use for small set of things)
[a,b].join(''); doesn't, and it's faster (building a lot of text)

minification vs obfuscation (whitespace and comments vs changing names of thing)
crockford.com/javascript/jsmin.html and then gzipping.

JSON - used for data interchange; easy to parse. uses object literal.
to make json safe, there's a regex that checks before eval.


No comments: