I have a problem with lexical binding in JavaScript. This is my code:
.pipe(through.obj((url, enc, done)=>{
if(!url) return done();
request.head(url, (err, response)=>{
this.push(url + ' is ' + (err ? 'down' : 'up') + '\n');
done();
});
}))
I get this error:
TypeError: this.push is not a function
But when I use es5 function syntax like function(url,enc,done){...}:
.pipe(through.obj(function(url, enc, done){
if(!url) return done();
request.head(url, (err, response)=>{
this.push(url + ' is ' + (err ? 'down' : 'up') + '\n');
done();
});
}))
then my code works well.
In this case, how can I use this.push() with the Arrow Function?
I know about Arrow Function's lexical binding, but I have no idea about using this.
Thanks for reading my text.