This has been addressed, please see the answer located at -> Create a custom callback in JavaScript
Asked
Active
Viewed 125 times
-1
-
without seeing what's returned in your `"data"`... hard to tell – Roko C. Buljan Feb 16 '14 at 15:58
-
The returned data could be anything. Let us assume it is the responseText of google which contains the google.com source. – Jesse Feb 16 '14 at 15:58
-
3I don't understand what `eval()` has to do with invoking a callback. If you pass a function as a callback, then the function can just be called. The question really isn't clear. – Pointy Feb 16 '14 at 15:59
-
2replace `if (typeof (b) !== 'undefined') with `if (typeof (b) === 'function ') ` and do `b();` – Royi Namir Feb 16 '14 at 16:00
-
@yivi - Why are you responding to a 7 year old question that I already edited 6 years ago to include the same link listed in your comment? – Jesse May 16 '21 at 12:35
1 Answers
2
You can use b()
to invoke the function "b" if it is a function. You can also use the apply method to invoke a function. On the subject of callbacks, you may be interested in this article about the Promise API, since it provides an example of "get" and "getJSON" method that are consistent with this API.

Michael Aaron Safyan
- 93,612
- 16
- 138
- 200