Reputation: 897
I need to assign the same anonymous arrow function to two different properties of the same object, which is defined with curly braces. E.g. now I have:
let testObject = {a: (a) => a+1, b: (a) => a+1};
And I want something like (pseudo-code):
let testObject = {a: b: (a) => a+1};
I actually know how to solve that problem (that is not a problem). But if there could be some way to assign the same intermediate (neither the variables, nor the primitives) values to two or more object properties like in a pseudo-code above, that would be very useful, isn't it?
Upvotes: 0
Views: 93
Reputation: 42460
No, not in the way you describe.
You could assign the function to a variable, but then it's not anonymous anymore:
const myFunc = a => a + 1;
const testObject = {a: myFunc, b: myFunc};
Upvotes: 2