Because this in arrow functions is lexically bound, they cannot be used in providing a transform function to a stream.Transform object, in which this.push is used to return data. See the following example:
transform.prototype._transform=(data,encoding,callback)=>{this.push(data);// this.push is undefined because this is//lexically bound and refers to the enclosing scopecallback();}The callback function already accepts the output of the transform as its second argument. The following works:
transform.prototype._transform=function(data,encoding,callback){callback(null,data);}In light of the fact that moving forward we're going to see a lot more people using the Arrow Function syntax, perhaps we should consider deprecating this.push(data), or at least changing the docs so that the callback(null,data); pattern is recommended moving forward?
I'd be very happy to submit a PR to the docs if there's any consensus on the right solution for this.
Because
thisin arrow functions is lexically bound, they cannot be used in providing a transform function to a stream.Transform object, in whichthis.pushis used to return data. See the following example:The callback function already accepts the output of the transform as its second argument. The following works:
In light of the fact that moving forward we're going to see a lot more people using the Arrow Function syntax, perhaps we should consider deprecating
this.push(data), or at least changing the docs so that thecallback(null,data);pattern is recommended moving forward?I'd be very happy to submit a PR to the docs if there's any consensus on the right solution for this.