This document discusses Javascript and provides an overview of key concepts like objects, arrays, functions, scope, this, and best practices. It covers object-oriented aspects like prototypes and inheritance. It also discusses tools like jQuery, debuggers, and build tools.
20. Prototypical
Inheritance
new Constructor();
Returns a new object with a link to
Constructor.prototype
Monday, October 4, 2010
21. Prototypical
Inheritance
Object.create = function(o) {
function F() {}
F.prototype = o;
return new F();
}
Monday, October 4, 2010
22. Arrays
• Array inherits from object
• Indexes are converted to strings
• Magic length property
• Always one larger than the highest int
property
Monday, October 4, 2010
37. Scope
The function is the scope of the
variables
Monday, October 4, 2010
38. Invocation Forms
• •Function form
sleep(10)
• •Method form
kjell.sleep(10)
• kjell[“sleep”](10)
• Constructor form
• new sleep(10)
• •Apply form
sleep.apply(rudolph, 10)
Monday, October 4, 2010
39. this
Invocation
this is an extra this
Form
dynamic the global
parameter that function
object
depends on the method kjell
calling form
constructor a new object
apply rudolph
Monday, October 4, 2010
40. arguments
• A special array like, DYNAMIC,
parameter
• All the arguments of the invocation
Monday, October 4, 2010
41. function sum() {
var i,
n = arguments.length,
total = 0;
for (i = 0; i < n; i += 1) {
total += arguments[i];
}
return total;
}
sum(1, 2, 3, 4);
Monday, October 4, 2010
42. Dynamic Compilation
• eval
• Evaluates a string and returns the result.
• new Function(parameterArray,
codeString)
• Creates and returns a function.
• var add=new Function("a", "b", "return a+b;");
Monday, October 4, 2010
43. Global Object
• Container for all variables
• On browsers window == global
• Any var not declared is global
• Global variables are Dangerous
Monday, October 4, 2010