From A Drip of Javascript: Object Equality in Javascript :
(摘自Java滴:JavaScript中的对象平等 :)
... Primitives like strings and numbers are compared by their value, while objects like arrays, dates, and plain objects are compared by their reference .
(...诸如字符串和数字之类的基元通过它们的值进行比较,而诸如数组,日期和普通对象之类的对象则通过其引用进行比较 。)
That comparison by reference basically checks to see if the objects given refer to the same location in memory.(通过引用进行的比较基本上检查了给定的对象是否引用了内存中的相同位置。)
Here is an example of how that works.(这是一个如何工作的例子。)
var jangoFett = { occupation: "Bounty Hunter", genetics: "superb" }; var bobaFett = { occupation: "Bounty Hunter", genetics: "superb" }; var callMeJango = jangoFett; // Outputs: false console.log(bobaFett === jangoFett); // Outputs: true console.log(callMeJango === jangoFett);
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…