修改自执行函数中的参数 [英] Modify arguments in self executing function
本文介绍了修改自执行函数中的参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我希望能够修改传递给自执行函数的参数。
I want to be able to modify the arguments passed to a self executing function.
以下是一些示例代码:
var test = 'start';
(function (t) {t = 'end'} )(test);
alert(test) //alerts 'test'
和这里是一个小提琴。变量 test
没有改变。我如何改变它,如在引用传递中?
And here is a fiddle. The variable test
has not changed. How can I alter it, as in pass-by-reference?
推荐答案
传入对象
,它是传递参考:
var test = {
message: 'start'
};
(function (t) {t.message = 'end'} )(test);
alert(test.message)
FYI,数组
也是传递参考。
这篇关于修改自执行函数中的参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文