Is there an equivalent in JavaScript for PHP\'s reference passing of variables?
[PHP]:
function addToEnd(&$theRefVar,$str) { $theRefVar.=$str; } $myVar=\"H
The other answers/comments describe the situation well enough, but I thought I'd offer and alternative if you need that style of functionality, by using a callback.
var someText = "asd";
addToEnd(someText, "fgh", function(val) { someText = val; });
and
function addToEnd(original, str, setValue)
{
setValue(original += str);
}
but a better solution would be
var someText = "asd";
someText = addToEnd(someText, "fgh");
and
function addToEnd(original, str)
{
return original += str;
}