2017-08-26 166 views

回答

3

Documentation

The following syntax with the new operator will throw a TypeError:

var sym = new Symbol(); // TypeError

This prevents authors from creating an explicit Symbol wrapper object instead of a new symbol value and might be surprising as creating explicit wrapper objects around primitive data types is generally possible (for example, new Boolean, new String and new Number).

只需使用Symbol作爲一個函數

var symbol = Symbol(4); 
 

 
console.log(typeof symbol); // outputs 'symbol'

+0

非常感謝@Suren,它的工作原理:)從來沒有想過的官方文檔... – Dev

相關問題