I'm trying to pass in an additional parameter to the callback function in a map. The value is not passed when I use es6 syntax for callback function and in map.
Here is the es6 map and callback function
const convertEvents = action.payload.map(item => convertEvent(item), { role: 'teacher' });
const convertEvent = (item) => {
console.log('----------convertEvent role----------');
console.log(this.role);
return item;
};
But when I used old javascript syntax the value is passed and the code works correctly
const convertEvents = action.payload.map(convertEventRole, { role: 'teacher' });
function convertEventRole(item) {
console.log('----------convertEvent role----------');
console.log(this.role);
return item;
}
Can you tell me why the es6 code didn't work?