I want my client to specify a predicate function that returns True or False based on an argument to the function. The server takes this function and applies it to some data.
The solution I’ve come up with is not a nice one. I use the browser’s function.toString() method and call eval() on the server side. Aside from the obvious security implications, it doesn’t seem clean.
I am using socket.io for communication, and passing objects is completely seamless. Is there a way to do this for functions?
I think what you want is https://github.com/substack/dnode . It doesn’t use .toString at all, but will let you call remote functions and get the results in a natural way. Check out the examples!
Edit: I forgot to mention, dnode uses socket.io underneath.