Symbol() 函数不能用作构造函数,与 new 关键字一起使用。这样做是为了避免创建符号包装对象,像使用Boolean 、 String 或 Number 那样,它们都支持构造函数且可用于初始化包含原始值的包装对象:
let myBoolean = new Boolean();
console.log(typeof myBoolean); // "object"
let myString = new String();
console.log(typeof myString); // "object"
let myNumber = new Number();
console.log(typeof myNumber); // "object"
let mySymbol = new Symbol(); // TypeError:
//Symbol is not a constructor
如果你确实想使用符号包装对象,可以借用 Object() 函数:
let mySymbol = Symbol();
let myWrappedSymbol = Object(mySymbol);
console.log(typeof myWrappedSymbol); //"object"