Forum Moderators: open

Message Too Old, No Replies

How to make an assignment reference the left operand

         

csdude55

8:46 pm on Dec 12, 2022 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



This is really just for fun, and my own education.

Let's say that I have this:

str = func(str);

function func(oldStr) {
// do stuff
return newStr;
}

Is there a way to modify func() so that, if oldStr is not explicitly defined, it would use the value of str (the left operand of the assignment)?

I know that I could do this, of course:

function func(oldStr = str)

but in production I wouldn't know the name of the variable that was assigned. So I'm trying to figure out if there's a built-in variable that equals the value of the left hand operator.

The end goal is to be able to use str = func(); without typing str twice :-)

Fotiman

8:12 pm on Dec 13, 2022 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



The short answer is no, there's no built-in variable that equals the value of the left hand operator.