Solucio this

De wikiserver
La revisió el 17:44, 30 oct 2014 per Jnoguera (Discussió | contribucions)
(dif) ← Versió més antiga | Versió actual (dif) | Versió més nova → (dif)
Dreceres ràpides: navegació, cerca
var myApp = function(){
  var name = "World"
  var sayHello = function(){
    console.log( 'Hello, ' + this.name );
  };
  sayHello(); // invoca la función
};
 
myApp(); // Hello,



var name = "Strange World";       //variable de ambit global
var myApp = function(){
  var name = "World"             //variable de ambit local
  var sayHello = function(){
    console.log( 'Hello, ' + this.name );        //aquest this es refereix a Window
  };
 
  sayHello();
 
};
 
myApp(); // Hello, Strange World