I know the following code can access outer this.
var o = function() {
var that = this;
this.a = 1;
$('html').click(function() {
alert(that.a);
});
}
new o();
But I don't wanna use two variable names(for example, this and that) for the same one object.
And I don't wanna repeatedly write var that = this
on every class.
I think the following code which uses _this instead of that is a little bit simpler.
var o = function() {
var _this = this;
this.a = 1;
$('html').click(function() {
alert(_this.a);
});
}
new o();
But are there other simpler and shorter ways?