var me = null;
var testFn = (function() {
me = this;
return {
me1: me,
fn1 : function() {
me = this;
return {
me2 : me,
fn2 : function() {
me = this;
return {
me3: me
}
}
}
}
}
})();
OR:
var testFn = (function() {
var me = this;
return {
me1: me,
fn1 : function() {
var me = this;
return {
me2 : me,
fn2 : function() {
var me = this;
return {
me3: me
}
}
}
}
}
})();
Between two segments given above, which one is best way to referencing this. Is there any other way best, please suggest.
Thanks…..
I would recommend using the second approach because me is declared inside a closure so iot doesn’t pollute context where it is not needed. It is also clearer to which context me belongs too.