为什么我不能将 Symbol 定义为构造函数?
Why can't I define Symbol as a constructor?
这是我的 Javascript (paperjs) 代码片段:
var symbol = new Symbol(path);
它给出警告 - "Do not use Symbol as a constructor"
这里还有什么我可以做的来消除那个警告吗?
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'
这是我的 Javascript (paperjs) 代码片段:
var symbol = new Symbol(path);
它给出警告 - "Do not use Symbol as a constructor"
这里还有什么我可以做的来消除那个警告吗?
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'