Use fn.call()
or fn.apply()
to set what you want the value of this
to be. See references for call or apply at MDN.
addEvent('mybutton','touchstart', function(){
if(window['touchmoved']==false) {
hover.call(this);
}
});
Both .call()
and .apply()
allow you to specify what you want the this
pointer to be in the called function.
.call()
lets you pass specific additional arguments that you want the called function to receive like this:
fn.call(this, true, "foo")`
.apply()
is used when the arguments you want to pass to the called function are in an array and you just pass the array of arguments like this:
var args = [true, "foo"];
fn.apply(this, args);
.apply()
is often used with the built-in arguments object to pass the existing arguments on to the called function (though there are other reasons to use it too):
fn.apply(this, arguments);