Skip to content

Commit 3e0057d

Browse files
brendanashworthbnoordhuis
authored andcommitted
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: nodejs#214 Reviewed-By: Ben Noordhuis <[email protected]>
1 parent 0f3d7e6 commit 3e0057d

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

lib/dgram.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ Socket.prototype.bind = function(port /*, address, callback*/) {
170170
if (port instanceof UDP) {
171171
replaceHandle(self, port);
172172
startListening(self);
173-
return;
173+
return self;
174174
}
175175

176176
var address;
@@ -231,6 +231,8 @@ Socket.prototype.bind = function(port /*, address, callback*/) {
231231
startListening(self);
232232
}
233233
});
234+
235+
return self;
234236
};
235237

236238

test/parallel/test-dgram-bind.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,6 @@ socket.on('listening', function () {
2929
socket.close();
3030
});
3131

32-
socket.bind(); // should not throw
32+
var result = socket.bind(); // should not throw
33+
34+
assert.strictEqual(result, socket); // should have returned itself

0 commit comments

Comments
 (0)