In addition to SLaks answers , in ECMAScript 5th Edition implementations you can use the method bind:
num1.attachEvent("onkeypress", validateNum.bind(null, num1, num2));
In implementations that do not support the method, you can use the Prototype JS framework or simply add a method to the prototype function with this fragment:
if (!('bind' in Function.prototype)) {
Function.prototype.bind= function(owner) {
var that= this;
var args= Array.prototype.slice.call(arguments, 1);
return function() {
return that.apply(owner,
args.length===0? arguments : arguments.length===0? args :
args.concat(Array.prototype.slice.call(arguments, 0))
);
};
};
}
source
share