Javascript是等于符号引用对象还是将其克隆? [英] Does Javascript equal sign reference objects or clones them?
本文介绍了Javascript是等于符号引用对象还是将其克隆?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在MyApp.something.BigObject
中,我有一个内存昂贵的对象,我喜欢这样做var theObject = MyApp.something.BigObject;
.我的问题是,这会占用两倍的内存吗?
In MyApp.something.BigObject
I have a memory expensive object and I like to do this var theObject = MyApp.something.BigObject;
. My question is would that take up double the memory or not?
推荐答案
等号"是赋值运算符.如果RHS是对象,则将引用分配给LHS,它不会克隆或复制该对象.
The "equals sign" is the assignment operator. If the RHS is an object, then a reference is assigned to the LHS, it does not clone or copy the object.
所以给定了:
var obj = {};
var b = obj;
obj 和 b 都引用相同的对象.
both obj and b reference the same object.
这篇关于Javascript是等于符号引用对象还是将其克隆?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文