修改自执行函数中的参数 [英] 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?
推荐答案
传入一个object
,它是pass-by-reference:
var test = {
message: 'start'
};
(function (t) {t.message = 'end'} )(test);
alert(test.message)
仅供参考,Array
也是传递引用.
这篇关于修改自执行函数中的参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文