It really depends on a number of factors. Here are a few considerations:
Historically, functions created from .bind()
have been slower.
The bound this
can't change its value, while the variable can. (Guessing you expect it to not change here.)
You'll be losing the element reference, though you can still get it via event.currentTarget
.
One other alternative to consider is to make your object implement the Event Listener interface. That will let you pass the object itself as the handler, and will invoke your implementation of the handleEvent()
method that you provide.
Then the this
value will automatically be your object.
So if your this
is an object that comes from a constructor, you could do this:
function MyCtor() {
// your constructor
}
// This implements the `Event Listener` interface
MyCtor.prototype.handleEvent = function(event) {
// ------v----should be "load"
return this[event.type](event)
};
// This is the `load` handler
MyCtor.prototype.load = function(event) {
this.emit({
type: "load",
asset: event.currentTarget
});
};
And then bind the handler like this:
asset.addEventListener("load", this, false);
Now your value of this
in the handle event will be your object so you can call its other methods, and neither .bind
nor a closure variable were needed.