I want to be able to modify the arguments passed to a self executing function.
Here is some sample code:
var test = 'start';
(function (t) {t = 'end'} )(test);
alert(test) //alerts 'test'
And here is a fiddle. The variable test has not changed. How can I alter it, as in pass-by-reference?
Pass in an object, it is pass-by-reference:
var test = {
message: 'start'
};
(function (t) {t.message = 'end'} )(test);
alert(test.message)
FYI, Array is also pass-by-reference.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With