Symbol
唯一
let hd = Symbol("angdh");
let af = Symbol("jingchang");
console.log(hd==af);
console.log(hd.toString());
console.log(hd.description);
// false
// Symbol(angdh)
// angdh
反复利用
let csm = Symbol.for("am");
let fsm = Symbol.for("am");
console.log(csm==fsm);
// true
let saf = Symbol.keyFor(csm);
console.log(saf);
//am
-------------------
let user1 = {
name:"tom",
key:Symbol()
};
let user2 = {
name:"tom",
key:Symbol()
};
let grade = {
[user1.key]:{js:100},
[user2.key]:{js:23}
};
console.log(grade[user2.key]);