唯一标识符,可用作对象的唯一属性值
// Here are two symbols with the same description:
letSym1=Symbol("Sym")
letSym2=Symbol("Sym")
console.log(Sym1===Sym2)// returns "false"// Symbols are guaranteed to be unique.// Even if we create many symbols with the same description,// they are different values.
letSym=Symbol("Sym")
alert(Sym.toString()) // Symbol(Sym), now it works
let_Sym=Symbol("Sym");
alert(_Sym.description); // Sym
Symbol.keyFor(Symbol.for("tokenString"))==="tokenString" // true
网友评论