Skip to content

Commit e7b8400

Browse files
originalfooFishrock123
authored andcommitted
http: replace finish() callback with arrow function
Take advantage of arrow function lexical `this` to avoid defining a `self = this` var which was only used once. Code relating to the `finish` event was split in to two areas of the parent function. Gathered it together to clarify association within the script. Fixes: #7295 PR-URL: #7378 Reviewed-By: Stephen Belanger <admin@stephenbelanger.com> Reviewed-By: Brian White <mscdex@mscdex.net> Reviewed-By: Fedor Indutny <fedor.indutny@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 44bc638 commit e7b8400

1 file changed

Lines changed: 7 additions & 8 deletions

File tree

‎lib/_http_outgoing.js‎

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -546,14 +546,6 @@ OutgoingMessage.prototype.end = function(data, encoding, callback) {
546546
returnfalse;
547547
}
548548

549-
varself=this;
550-
functionfinish(){
551-
self.emit('finish');
552-
}
553-
554-
if(typeofcallback==='function')
555-
this.once('finish',callback);
556-
557549
if(!this._header){
558550
if(data){
559551
if(typeofdata==='string')
@@ -581,6 +573,13 @@ OutgoingMessage.prototype.end = function(data, encoding, callback) {
581573
this.write(data,encoding);
582574
}
583575

576+
if(typeofcallback==='function')
577+
this.once('finish',callback);
578+
579+
constfinish=()=>{
580+
this.emit('finish');
581+
};
582+
584583
if(this._hasBody&&this.chunkedEncoding){
585584
ret=this._send('0\r\n'+this._trailer+'\r\n','binary',finish);
586585
}else{

0 commit comments

Comments
 (0)