javascript - Pros and cons of this.myVar vs. var myVar -


this question has answer here:

var myfunction = function () {     this.myvar = 'something';     var myvar = 'else'; }; 

what pros , cons of 2 above, see them being used.

the main difference following:

var myfunc = function(){ this.x = 2; // want used outside of declaration }  var y = new myfunc(); console.log(y.x); // 2  var myfunc2 = function(){ var x = 3; // want use inside function }  var z = new myfunc2(); console.log(y.x); // undefined 

so this. variable accessible , var won't be.


Comments

Popular posts from this blog

android - net_scheduler holding wakelock -

sql - MySQL : Getting Entries from a many-to-many table -

java - Retrieving data from database using jsp (Hibernate + Spring + Maven) -