I wonder is there any diffrence, in below codes:
function x(){
var a = 1;
}
and:
function x(){
this.a = 1;
}
I wonder is there any diffrence, in below codes:
function x(){
var a = 1;
}
and:
function x(){
this.a = 1;
}
The first creates a locally-scoped variable, which will not be retained after the function exits (unless by a closure created inside the function).
The second creates an expando property on the this
object, possibly overwriting any previous value for that property.
The scope.
this.a will check for a window property a, and makes it global
function x(){
this.a = 1;
}
is equal to
var instantance_a;
function x(){
instantance_a = 1;
}
or rather a global property lik
window.a