Sometimes you need to pass a JavaScript function in a JSON response from the server and use it on the client.
This post walks through how. First, make sure you understand how the reviver function and JSON.parse work — see the previous post.
The trick is to put the function body as a string in the JSON, then turn it back into a function on the client using the reviver:
Hope this helps.