1

Here's what I want to do:

function someEvent(e) {
}

onxxxx="someEvent()"

and turn that into:

function someEvent(e, arg1, arg2) {
}

onxxxx="someEvent(???)"

So basically, I want to pass other arguments including the default event one, but I'm not sure quite how to

Oztaco
  • 3,399
  • 11
  • 45
  • 84
  • possible duplicate of http://stackoverflow.com/questions/9417121/is-there-any-way-of-passing-additional-data-via-custom-events – Will P. Feb 21 '14 at 23:04
  • Why do you need to pass params to your event's callback ? – htatche Feb 21 '14 at 23:04
  • @WillP. In essence yes, but no because I need to use the HTML attribute for the event, not addEventListener – Oztaco Feb 21 '14 at 23:07
  • @htatche So that I don't need to write one function for many slightly different pieces of code – Oztaco Feb 21 '14 at 23:07
  • How are you binding the event? – Will P. Feb 21 '14 at 23:08
  • You could have function1, function2, function3, functionX, each one calling `someEvent()` with a different set of arguments, and then call one of those functions from onxxx. But I still don't see a real need for it... – htatche Feb 21 '14 at 23:10

2 Answers2

2

You can pass the event object as an argument:

onxxxx="someEvent(event, arg1, arg2);"

event must be literal event here.

Within the eventhandler function you find them like so:

function someEvent(e, a, b) {
    // e === event object
    // a === arg1
    // b === arg2
}
Teemu
  • 22,918
  • 7
  • 53
  • 106
0

You could use anonymous functions:

var arg1 = "12345 - test", arg2 = 42;

onxxxxx = function(e) {
    someEvent.call(this, e, arg1, arg2);
};
Toothbrush
  • 2,080
  • 24
  • 33