Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Passing a JavaScript function without executing

I have a callback without parameters and it stored in an object with no execution like so:

{callback:function(){ do my thing }}

Then I realized I needed to send in some parameters, and all the sudden JS is executing the function upon discovery:

{callback:(function(e){ do my thing with e })(event)}

Is there a way to do this without it executing immediately?

like image 868
Mark Löwe Avatar asked Feb 18 '26 12:02

Mark Löwe


1 Answers

The problem is in your second snippet you are invoking the function with (event).

You should just be able to remove it and when the callback is executed, if an event is passed to the callback it will be e:

{callback:function(e){ do my thing with e }}
like image 62
marteljn Avatar answered Feb 21 '26 01:02

marteljn