Example of what i'm trying to achieve
I want to make an object in react which will calculate one its key value from other keys using this function and the 'this' keyword so that I can use this function dynamically with many input fields object.
func = function (c) {
return this.a + this.b + c;
};
obj1 = {
a: 1,
b: 2,
value: func(5),
};
obj2 = [
{ a: 2, b: 3, value: func(6) },
{
a: 4,
b: 5,
value: func(7),
},
];
// expected result
console.log(obj1.value); // 8
console.log(obj2[0].value); // 16