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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
“等号”是赋值运算符。如果 RHS 是一个对象,则将引用分配给 LHS,它不会克隆或复制该对象。
因此:
obj 和 b 都引用同一个对象。
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.
So given:
both obj and b reference the same object.