Passing a named function to Javascript
4 answers
The code you have now, which wraps the call in another anonymous function, works fine and is a widely used pattern in Javascript.
If you want to remove the anonymous function, you can use a function reference with a method instead bind()
. Try the following:
callback(foo.bind(this, params));
+2
source to share