Solucio this

De wikiserver
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