dynamically typed with var
everything is object including primitives
functions are first class objects treated just like any other variable
OO, procedural, functional
Patterns:
- http://shichuan.github.io/javascript-patterns/
- http://addyosmani.com/resources/essentialjsdesignpatterns/book/
Use JSON notation in defining objects, arryays var v = ['test'];
Object - unordered collection key value pairs
decalre functions like a variable with equals - var myfunction = function () {}
Use functions to encapsulate context such as with the 'this'
Here is an example of a closure:
var colors = ['red' , 'blue', 'yellow' ] ;
console.log('number of colors ' + colors.length);
for (var i=0;i<colors.length;i++){
setTimeout ((function(i){
return function (){
console.log(colors);
console.log(i) ;
console.log(colors[i]);
};
}) (i), 100);
}
Function scope or Global scope
this keyword - owner of function we are executing
variable must be assigned to something for it to have 'this' meaning
prototype - is an object in which other objects inherits properties
every object has one
__proto__ in the debugger
Use it to define the blue print of the class
More...
No comments:
Post a Comment