I have a function that reads an http stream, combines the data events, and passes the response as a joined string. If I pass the 'data' event a function in the form of c => body.push(c)
it works as expected. However, if I pass it body.push
the content is never added to the array. Is there a reason generic prototypes can't be passed as parameters?
Here's my function:
const requestPromise = function(resolve, reject) {
return (response) => {
let body = [];
response.on('data', body.push);
response.on('end', () => {
body = body.join('');
if (body == "") {
reject("Body is empty");
} else {
resolve(body);
}
});
};
};