我在 d3 example 中发现了这种奇怪的语法
var heatmapChart = function(tsvFile) {
d3.tsv(tsvFile,
function(d) {
return {
day: +d.day,
hour: +d.hour,
value: +d.value
};
},
加了什么
day: +d.day,
意思是?
最佳答案
这是一元转换。这是转换为数字的简写方法。来自 ECMAScript docs :
The unary + operator converts its operand to Number type.
The production UnaryExpression : + UnaryExpression is evaluated as follows:
Let expr be the result of evaluating UnaryExpression.
Return ToNumber(GetValue(expr)).
var a = "45"; //typeof String
a = +a; // now typeof Number
关于javascript - JS对象键: plus value syntax,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39964556/