function proxy (frontend, backend, capture){
  switch(frontend.type+'/'+backend.type){
    case 'push/pull':
    case 'pull/push':
    case 'xpub/xsub':
      if(capture){

        frontend.on('message',function (){
          backend.send([].slice.call(arguments));
        });

        backend.on('message',function (){
          frontend.send([].slice.call(arguments));

          //forwarding messages over capture socket
          capture.send([].slice.call(arguments));
        });

      } else {

        //no capture socket provided, just forwarding msgs to respective sockets
        frontend.on('message',function (){
          backend.send([].slice.call(arguments));
        });

        backend.on('message',function (){
          frontend.send([].slice.call(arguments));
        });

      }
      break;
    case 'router/dealer':
    case 'xrep/xreq':
      if(capture){

        //forwarding router/dealer pack signature: id, delimiter, msg
        frontend.on('message',function (id,delimiter,msg){
          backend.send([id,delimiter,msg]);
        });

        backend.on('message',function (id,delimiter,msg){
          frontend.send([id,delimiter,msg]);

          //forwarding message to the capture socket
          capture.send(msg);
        });

      } else {

        //forwarding router/dealer signatures without capture
        frontend.on('message',function (id,delimiter,msg){
          backend.send([id,delimiter,msg]);
        });

        backend.on('message',function (id,delimiter,msg){
          frontend.send([id,delimiter,msg]);
        });

      }
      break;
    default:
      throw new Error('wrong socket order to proxy');
  }
}
JS based on API characteristics of the native zmq_proxy()