So I’m trying to do the following;
var myVar;
function testFunction(args){
args.cacheVar = new Date();
}
testFunction({cacheVar:myVar});
but instead of changing the value of myVar, its changing the value of args.cacheVar.
What I would like to happen is for myVar = new Date(). not args.cacheVar.
How can I accomplish this with my current setup? (using arguments)
You are not passing
myVarto your function. You are passing an object. That object may get updated, but since you do not have a reference to it anywhere, nothing happens.You need to save your object as a variable before passing it.