Jul 9, 2012

Javascript Note from Book: javascript: the good parts


  1. single number type, internally it's 64-bits floating point. (no separate integer type!)
  2. all characters  are 16 bits wide.  "A" === "\u0041"
  3. Variable is FUNCTION scope, instead of BLOCK scope.  Use "var" to define a variable in a function, better at the top of function. Otherwise, the variable's scope will be global.
  4. The default value can be filled with default: var myVal = Data["src"] || "no-data" ; 
  5. Objects are passed by reference. They are never copied.
  6. If the object lacks the property name, then JS attempts to get it from the prototype object. ==> hasOwnProperty()
  7. Removing a property from one object by using "delete" may allow a property from the prototype to shine through
  8. if ( typeof   myVal !== 'function' ) ...


Function

  1. Function object are linked to Function.prototype and can have methods.
  2. Functions can be defined inside of other functions.
  3. Closure:  the function object created by a function literal contains a link to that outer context.
  4. function foo( argA, argB, argC){...}       foo("one", "two");  ==>  argC will be undefined
  5. Be careful about the "this" variable.
  6. Function always returns a value, or undefined is returned instead.
  7. Closure usage !!!
  8. If methods return this, cascade calls can be enabled.   getElement("id").moveUp().color('red').tip('abc');
  9. ...
TBC.....

No comments:

Post a Comment