Solucio this

De wikiserver
La revisió el 14:47, 30 oct 2014 per Jnoguera (Discussió | contribucions) (Es crea la pàgina amb «<source lang="javascript"> var myApp = function(){ var name = "World" var sayHello = function(){ console.log( 'Hello, ' + this.name ); }; sayHello(); // Invok…».)
(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(); // Invoke the function
};
 
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