... come to think of it, as there is no reliance on this, the return value doesn't have to be an object anymore.
constinitialValue=0;constvalueTuple=(function(init){letval=init;constgetValue=()=>val;constsetValue=(newVal)=>{val=newVal;};return[getValue,setValue];})(initialValue);const[current,set]=valueTuple;console.assert(current()===initialValue,'initialization failed');set(1);console.assert(current()===1,'set to 1 failed');set(3);console.assert(current()===3,'set to 3 failed');
Though perhaps now we aren't revealing a "module" anymore.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
... come to think of it, as there is no reliance on
this
, the return value doesn't have to be an object anymore.Though perhaps now we aren't revealing a "module" anymore.