简体   繁体   English

在javascript中强制按引用传递

[英]Force pass by reference in javascript

Is there any way to force pass by reference in javascript?有没有办法在javascript中强制通过引用传递? I have read that objects are passed as 'copy of object reference' or call-by-sharing but I want the changes across the functions to be reflected across the sender and the receiver.我已经读过对象作为“对象引用的副本”或共享调用传递,但我希望跨函数的更改在发送方和接收方之间反映出来。 Current design prevents me from declaring it as a global variable.当前的设计阻止我将其声明为全局变量。 Any ideas on how to handle this?关于如何处理这个的任何想法?

For example, considering the code below ->例如,考虑下面的代码 ->

在此处输入图片说明

Now when I execute function1, I get ->现在,当我执行 function1 时,我得到 ->

在此处输入图片说明

How do I ensure that function1 has the changed/updated values?如何确保 function1 具有更改/更新的值?

I have found this https://codeburst.io/javascript-pass-by-value-and-pass-by-reference-in-javascript-fcf10305aa9c我发现了这个https://codeburst.io/javascript-pass-by-value-and-pass-by-reference-in-javascript-fcf10305aa9c

However, when a variable refers to an object which includes array, the value is the reference to the object但是,当变量引用包含数组的对象时,该值是对该对象的引用

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM