Below is my code.
What I'm wondering is how to pass the data of the return parameter in the arrow function 'response' when passing the parameter to the variable 'ok'.
const response = (statusCode, formatter = null) => {
const hasFormatter = typeof formatter === 'function';
const format = hasFormatter ? formatter : _ => _;
return (data = null) => {
const response = {
statusCode: statusCode
};
// Why is the data delivered??
if (data) {
response.body = format(data);
}
return response;
}
};
const ok = response(200, JSON.stringify);
// Here, I put the parameter value({foo: 'bar'}) in the variable 'ok'.
console.log( ok({foo: 'bar'}) );
// {statusCode: 200, body: "{"foo":"bar"}"}