title: How to pass function/callback to child process in Node.js?
body: <p>Let's say I have a <code>parent.js</code> containing a method named <code>parent</code></p>
  
  <pre><code>var childProcess = require('child_process');
  
  var options = {
      someData: {a:1, b:2, c:3},
      asyncFn: function (data, callback) { /*do other async stuff here*/ }
  };
  
  function Parent(options, callback) {
      var child = childProcess.fork('./child');
      child.send({
          method: method,
          options: options
      });
      child.on('message', function(data){
          callback(data,err, data,result);
          child.kill();
      });
  }
  </code></pre>
  
  <p>Meanwhile in <code>child.js</code></p>
  
  <pre><code>process.on('message', function(data){
      var method = data.method;
      var options = data.options;
      var someData = options.someData;
      var asyncFn = options.asyncFn; // asyncFn is undefined at here
      asyncFn(someData, function(err, result){
          process.send({
              err: err,
              result: result
          });
      });
  });
  </code></pre>
  
  <p>I was wondering if passing functions to child process is not allowed in Node.js.</p>
  
  <p>Why would <code>asyncFn</code> become <code>undefined</code> after it is sent to the <code>child</code>?</p>
  
  <p>Is it related to <code>JSON.stringify</code>?</p>