-1

I have following code and wondering if I can apply as arrow function on line data({value}: {value: string}) {return func(value); },

function func(value: string){
    return `${value} has been formated`
}
const rowData = {
  height: 20,
  data({value}: {value: string}) {
    return func(value);
  },
  width: 130,
};

console.log(rowData.data({value:'aaaa'})) //aaaa has been formated

I have try data({value}: {value: string}) => func(value), but it does not seem to work

jacobcan118
  • 7,797
  • 12
  • 50
  • 95

1 Answers1

1

You can use this syntax:

const rowData = {
  // ...
  data: ({value}: {value: string}) => func(value),
  // ...
};

There's not a significant advantage to this other than syntax, given you're not accessing this from the rowData object. The function will also be anonymous, which makes it unnamed in stack traces.

Cameron Little
  • 3,487
  • 23
  • 35