Content deleted Content added
m Dating maintenance tags: {{Citation needed}} |
→Symbol: modified the example to make it more clear; commented out a confusing snippet (if you understand it can you improve it?) |
||
Line 410:
<syntaxhighlight lang="javascript">
var x = Symbol(1);
var y = Symbol(1);
x === y; // => false
var symbolObject = {};
var normalObject = {};
// since x and y are unique,
// they can be used as unique keys in an object
x=Symbol(3);▼
symbolObject[x] = 1;
symbolObject[y] = 2;
arr[x]; // is now undefined▼
x=Symbol(1);▼
symbolObject[y]; // => 2
// as compared to normal numeric keys
normalObject[1] = 1;
normalObject[1] = 2; // overrides the value of 1
normalObject[1]; // => 2
// changing the value of x does not change the key stored in the object
▲x = Symbol(3);
// changing x back just creates another unique Symbol
▲x = Symbol(1);
symbolObject[x]; // => undefined
</syntaxhighlight>
"The Symbol wrapper also provides access to a [sic] variable free iterator."
<syntaxhighlight lang="javascript">
Line 432 ⟶ 449:
while ((exv=ex.next().value)!=undefined) console.log(exv); // displays 1,2,3,4
</syntaxhighlight>
-->
==Native objects==
|