• <i id='ZKxSm'><tr id='ZKxSm'><dt id='ZKxSm'><q id='ZKxSm'><span id='ZKxSm'><b id='ZKxSm'><form id='ZKxSm'><ins id='ZKxSm'></ins><ul id='ZKxSm'></ul><sub id='ZKxSm'></sub></form><legend id='ZKxSm'></legend><bdo id='ZKxSm'><pre id='ZKxSm'><center id='ZKxSm'></center></pre></bdo></b><th id='ZKxSm'></th></span></q></dt></tr></i><div id='ZKxSm'><tfoot id='ZKxSm'></tfoot><dl id='ZKxSm'><fieldset id='ZKxSm'></fieldset></dl></div>

      • <bdo id='ZKxSm'></bdo><ul id='ZKxSm'></ul>

        <small id='ZKxSm'></small><noframes id='ZKxSm'>

        <legend id='ZKxSm'><style id='ZKxSm'><dir id='ZKxSm'><q id='ZKxSm'></q></dir></style></legend>
      1. <tfoot id='ZKxSm'></tfoot>

        Node.js 中的解除绑定事件

        时间:2024-04-20

        <small id='R4Yqm'></small><noframes id='R4Yqm'>

          <tbody id='R4Yqm'></tbody>

          <tfoot id='R4Yqm'></tfoot>
          <i id='R4Yqm'><tr id='R4Yqm'><dt id='R4Yqm'><q id='R4Yqm'><span id='R4Yqm'><b id='R4Yqm'><form id='R4Yqm'><ins id='R4Yqm'></ins><ul id='R4Yqm'></ul><sub id='R4Yqm'></sub></form><legend id='R4Yqm'></legend><bdo id='R4Yqm'><pre id='R4Yqm'><center id='R4Yqm'></center></pre></bdo></b><th id='R4Yqm'></th></span></q></dt></tr></i><div id='R4Yqm'><tfoot id='R4Yqm'></tfoot><dl id='R4Yqm'><fieldset id='R4Yqm'></fieldset></dl></div>
          <legend id='R4Yqm'><style id='R4Yqm'><dir id='R4Yqm'><q id='R4Yqm'></q></dir></style></legend>

              <bdo id='R4Yqm'></bdo><ul id='R4Yqm'></ul>
                • 本文介绍了Node.js 中的解除绑定事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  Let's take stdin.on as an example. Callbacks to stdin.on stack, so if I write (in CoffeeScript)

                  stdin = process.openStdin()
                  stdin.setEncoding 'utf8'
                  stdin.on 'data', (input) -> console.log 'One'
                  stdin.on 'data', (input) -> console.log 'Two'
                  

                  then every time I hit return at the prompt, I get

                  One
                  Two
                  

                  My question is, is there any way to remove/replace a callback once bound? Or is the only approach to bind a proxy callback and manage state myself?

                  解决方案

                  You can use removeListener(eventType, callback) to remove an event, which should work with all kinds of emitters.

                  Example from the API docs:

                  var callback = function(stream) {
                    console.log('someone connected!');
                  };
                  server.on('connection', callback);
                  // ...
                  server.removeListener('connection', callback);
                  

                  So you need to have a variable that holds a reference to the callback, because obviously, it's otherwise impossible to tell which callback you want to have removed.

                  EDIT
                  Should be someone like this in CS:

                  stdin = process.openStdin()
                  stdin.setEncoding 'utf8'
                  
                  logger = (input) -> console.log 'One'
                  stdin.on 'data', logger
                  stdin.removeListener 'data', logger
                  
                  stdin.on 'data', (input) -> console.log 'Two'
                  

                  See: http://nodejs.org/docs/latest/api/events.html#emitter.removeListener

                  这篇关于Node.js 中的解除绑定事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:一组可供 Rails 应用程序使用的 CoffeeScript/JavaScript 类和方法 下一篇:Node.js 产生颜色?

                  相关文章

                    <i id='0OY8L'><tr id='0OY8L'><dt id='0OY8L'><q id='0OY8L'><span id='0OY8L'><b id='0OY8L'><form id='0OY8L'><ins id='0OY8L'></ins><ul id='0OY8L'></ul><sub id='0OY8L'></sub></form><legend id='0OY8L'></legend><bdo id='0OY8L'><pre id='0OY8L'><center id='0OY8L'></center></pre></bdo></b><th id='0OY8L'></th></span></q></dt></tr></i><div id='0OY8L'><tfoot id='0OY8L'></tfoot><dl id='0OY8L'><fieldset id='0OY8L'></fieldset></dl></div>
                  1. <legend id='0OY8L'><style id='0OY8L'><dir id='0OY8L'><q id='0OY8L'></q></dir></style></legend>

                    1. <small id='0OY8L'></small><noframes id='0OY8L'>

                    2. <tfoot id='0OY8L'></tfoot>
                      • <bdo id='0OY8L'></bdo><ul id='0OY8L'></ul>