What is the best approach for passing the this parameter of the init function to the change event handler and why?
Option 1 (using that = this).
SomeObject.prototype.init = function () {
var that = this;
this.$element.change(function () {
//do some some things with that.
that.
});
};
Option 2 (using event.data).
SomeObject.prototype.init = function () {
this.$element.change({object:this }, function (e) {
//do some some things with the event data.
e.data.object.
});
};
Or another (better) one?
Imho the first one is a bit nicer. A 3rd way (if you can use ECMA5) would be