I have a function that has named arguments.
I am trying to call the same function from different events without overwriting the values of the others previously assigned.
I have tried store the values of the previously clicked buttons in variables but that doesn't work.
Is there a way to call the functions and assign a single argument at a time without overwriting the others?
function mainFun({
val1,
val2,
val3
}) {
var value1 = val1,
value2 = val2,
value3 = val3;
// console.log(value1, value2, value3);
console.log(val1, val2, val3);
}
<button onclick="mainFun({val1 : 'Caller 1'})">First Event</button>
<button onclick="mainFun({val2 : 'Caller 2'})">Second Event</button>
<button onclick="mainFun({val3 : 'Caller 3'})">Third Event</button>
Trying to achieve:
On First Event > Caller 1 undefined undefined
On Second Event > Caller 1 Caller 2 undefined
On Third Event > Caller 1 Caller 2 Caller 3
Thanks in advance!