副本或指向对象的指针? [英] A copy or a pointer to an object?

查看:81
本文介绍了副本或指向对象的指针?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我在使用框架的浏览器窗口上创建一个大对象...



BLACKBOX = {}

BLACKBOX.historyobj = [];

BLACKBOX.somevariable =name

BLACKBOX.somevalue = 24

BLACKBOX.largearray = [....] ;

BLACKBOX.anotherarray = [....];

BLACKBOX.SortNumbers = function(a,b){return(parseInt(a)-parseInt(b) );};

等...



每帧使用一个变量,如



var BB = window.top.BLACKBOX



每个帧中的每个BB变量现在都拥有该对象的副本并使用更多内存,

或它只是指向窗口BLACKBOX ??



我尝试过:



多年来我一直在成功使用它

但是想知道这是否消耗更多内存如果

它只是制作副本每帧中的BLACKBOX。

If I create a large object on a browser window that uses frames...

BLACKBOX={}
BLACKBOX.historyobj=[];
BLACKBOX.somevariable="name"
BLACKBOX.somevalue=24
BLACKBOX.largearray=[....];
BLACKBOX.anotherarray=[....];
BLACKBOX.SortNumbers=function(a,b){return (parseInt(a)-parseInt(b));};
etc...

and each frame uses a variable like

var BB=window.top.BLACKBOX

does each BB variable in each frame now hold a copy of the object and use more memory,
or does it just point to the window BLACKBOX??

What I have tried:

I have been using this successfully for years
but wonder if this is consuming more memory if
it is just making copies of the BLACKBOX in each frame.

推荐答案

你所要做的就是学习JavaSc ript ..

...但即使有基本知识,你也应该单独测试......



All you have to do is learn JavaScript..
...but even with basic knowledge you should test it alone...

var o1 = {"name": "o1"};
var o2 = o1;
var o3 = o1.assign({}, o1);

o2.name = "o2";
o3.name = "o3";





检查 o1 o2 o3 最后......你有答案......



Check o1, o2 and o3 at the end... you have your answer there...


这篇关于副本或指向对象的指针?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆