From 3e0057dd61626890e1880ed1e609ef31ce39720b Mon Sep 17 00:00:00 2001 From: Brendan Ashworth Date: Mon, 29 Dec 2014 12:03:24 -0800 Subject: [PATCH] dgram: change Socket.bind() to return itself This commit changes `lib/dgram.js` Sockets to, when they are bound to a port / IP, return themselves. This is done in order to allow chaining of methods and be in accordance with the `lib/net.js` library. PR-URL: https://github.com/iojs/io.js/pull/214 Reviewed-By: Ben Noordhuis --- lib/dgram.js | 4 +++- test/parallel/test-dgram-bind.js | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/dgram.js b/lib/dgram.js index defa144bd1..6b1772e612 100644 --- a/lib/dgram.js +++ b/lib/dgram.js @@ -170,7 +170,7 @@ Socket.prototype.bind = function(port /*, address, callback*/) { if (port instanceof UDP) { replaceHandle(self, port); startListening(self); - return; + return self; } var address; @@ -231,6 +231,8 @@ Socket.prototype.bind = function(port /*, address, callback*/) { startListening(self); } }); + + return self; }; diff --git a/test/parallel/test-dgram-bind.js b/test/parallel/test-dgram-bind.js index 8ee67637fc..1fe615bb75 100644 --- a/test/parallel/test-dgram-bind.js +++ b/test/parallel/test-dgram-bind.js @@ -29,4 +29,6 @@ socket.on('listening', function () { socket.close(); }); -socket.bind(); // should not throw +var result = socket.bind(); // should not throw + +assert.strictEqual(result, socket); // should have returned itself