【发布时间】:2012-06-17 15:57:05
【问题描述】:
调用java脚本方法时如何通过引用传递原始变量(如字符串)? 相当于 C# 中的 out 或 ref 关键字。
我有一个像 var str = "this is a string"; 这样的变量,并将 str 传递到我的函数中,当我更改参数值时,我必须自动反映 str 的变化
function myFunction(arg){
// automatically have to reflect the change in str when i change the arg value
arg = "This is new string";
// Expected value of str is "This is new string"
}
【问题讨论】:
-
stackoverflow.com/questions/2423868/… alemjerus 对此的回答可能是您想要的。将其转换为对象。
-
@Dan,这似乎不是该功能的副本。在这里,OP 只是想知道在 JS 中通过引用传递函数参数的最佳方式;引用的问题涉及对函数对象本身的引用。
标签: javascript