[Groonga-commit] groonga/express-droonga at 25e4a69 [master] Fix wrong inheritance method

Back to archive index

Kouhei Sutou null+****@clear*****
Sat Jul 20 18:39:07 JST 2013


Kouhei Sutou	2013-07-20 18:39:07 +0900 (Sat, 20 Jul 2013)

  New Revision: 25e4a690ffda3b6310a809d557c7534b2fa188ec
  https://github.com/groonga/express-droonga/commit/25e4a690ffda3b6310a809d557c7534b2fa188ec

  Message:
    Fix wrong inheritance method
    
    "Child.prototype = new Parent()" should not be used. It has
    problem. See the below test script.
    
    "Child.prototype = Object.create(Parent.prototype)" should be used.
    
        var EventEmitter = require('events').EventEmitter;
    
        function Receiver() {
        };
    
        Receiver.prototype = new EventEmitter();
    
        Receiver.prototype.emitEvent = function() {
            this.emit("event");
        }
    
        receiver1 = new Receiver();
        receiver1.on("event", function() {console.log("receiver1")});
        receiver2 = new Receiver();
        receiver2.on("event", function() {console.log("receiver2")});
    
        receiver2.emitEvent();
        // -> receiver1
        // -> receiver2
        // receiver1 is also received the event that is emitted to receiver2.

  Modified files:
    lib/backend/receiver.js

  Modified: lib/backend/receiver.js (+1 -1)
===================================================================
--- lib/backend/receiver.js    2013-07-17 22:40:35 +0900 (c14f6a4)
+++ lib/backend/receiver.js    2013-07-20 18:39:07 +0900 (d06230b)
@@ -7,7 +7,7 @@ function MsgPackReceiver(port) {
   this._init();
 }
 
-MsgPackReceiver.prototype = new EventEmitter();
+MsgPackReceiver.prototype = Object.create(EventEmitter.prototype);
 
 MsgPackReceiver.prototype._init = function() {
   this._server = net.createServer(this._onConnect.bind(this));
-------------- next part --------------
HTML����������������������������...
Download 



More information about the Groonga-commit mailing list
Back to archive index