• <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 中的解除绑定事件

        Unbinding events in Node.js(Node.js 中的解除绑定事件)

        <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/Javascript: How to inject rails variables into (very) simple javascript(Rails/Javascript:如何将 rails 变量注入(非常)简单的 javascript)
                  quot;Each child in an array should have a unique key propquot; only on first time render of page(“数组中的每个孩子都应该有一个唯一的 key prop仅在第一次呈现页面时)
                  Rails 3.1 ajax:success handling(Rails 3.1 ajax:成功处理)
                  CoffeeScript always returns in anonymous function(CoffeeScript 总是以匿名函数返回)
                  Ordinals in words javascript(javascript中的序数)
                  getFullYear returns year before on first day of year(getFullYear 在一年的第一天返回前一年)

                    <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>
                      <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>
                            <tbody id='0OY8L'></tbody>
                            <bdo id='0OY8L'></bdo><ul id='0OY8L'></ul>