是否可以查看控制台上打印的两个 Javascript 对象是否是同一个实例(最好在 Chrome 中)
Is it possible to see if two Javascript objects that are printed on the console are the same instance (preferably in Chrome)
当我 运行 Chrome 中的以下代码时,我想看到 a
和 b
指的是同一个对象,但 c
不是。有办法吗?
let a = {x:1,y:2,z:3};
let b = a;
let c = {x:1,y:2,z:3};
console.log(a);
console.log(b);
console.log(c);
使用 "store as global variable" 功能。
右键单击每个输出上的 {x: 1, y: 2, z: 3}
文本,然后单击 "Store as global variable"。您将获得 3 个变量:
temp1
, temp2
, temp3
.
然后,试试这些:
temp1 == temp2
// output true
temp2 == temp3
// output false
提示:您可以通过这种方式访问任何变量(即使是那些在非常深的回调中的变量),只要您使用控制台输出它们即可。
当我 运行 Chrome 中的以下代码时,我想看到 a
和 b
指的是同一个对象,但 c
不是。有办法吗?
let a = {x:1,y:2,z:3};
let b = a;
let c = {x:1,y:2,z:3};
console.log(a);
console.log(b);
console.log(c);
使用 "store as global variable" 功能。
右键单击每个输出上的 {x: 1, y: 2, z: 3}
文本,然后单击 "Store as global variable"。您将获得 3 个变量:
temp1
, temp2
, temp3
.
然后,试试这些:
temp1 == temp2
// output true
temp2 == temp3
// output false
提示:您可以通过这种方式访问任何变量(即使是那些在非常深的回调中的变量),只要您使用控制台输出它们即可。