Skip to content

Commit

Permalink
dgram: change Socket.bind() to return itself
Browse files Browse the repository at this point in the history
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: #214
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
  • Loading branch information
brendanashworth authored and bnoordhuis committed Dec 29, 2014
1 parent 0f3d7e6 commit 3e0057d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 3 additions & 1 deletion lib/dgram.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -231,6 +231,8 @@ Socket.prototype.bind = function(port /*, address, callback*/) {
startListening(self);
}
});

return self;
};


Expand Down
4 changes: 3 additions & 1 deletion test/parallel/test-dgram-bind.js
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 3e0057d

Please sign in to comment.