AngularJS
- Add angular.js
- Add tag ng-app in HTML tag
- <html ng-app>
- ng-app : start AngulaJS
- ng = AngularJS
- {{ }}
JavaScript
- Functions
In this example the last line execute all the code.
var work = function(){
console.log("working");
}
var dowork = function (f){
try{
f();
}catch(ex){
console.log(ex);
}
}
dowork(work);
- Module
Modules allow to create object in JS
In this case is creating an object named "worker" and is created by "createWorker" that return an object with 2 methods
var createWorker = function() {
var count = 0;
var job1 = function(){
count +=1;
console.log(count);
};
var task2 = function(){
count +=1;
console.log(count);
};
return {
job1: job1,
job2: task2
};
};
var worker = createWorker();
worker.job1();
worker.job2();
- IIFE
Immediately Invoke Function Expression
- A function that it call itself
- Avoid to create global variables
(function(){
console.log("IIFE");
}());
Comentarios
Publicar un comentario