我正在尝试理解 HomeAssistant 前端源代码。我发现我不太理解函数定义。我不明白这个语法(model.entity 是一个字符串)...
export function createHasDataGetter(model) {
return [
['restApiCache', model.entity],
entityMap => !!entityMap,
];
}
看起来像这样:
返回[[字符串,字符串], bool ]
?
这个函数的 teturn 类型到底是什么?这只是 bool 吗?如果是,是否意味着entityMap是字符串数组?
最佳答案
参见"Truthy" on MDN :
In JavaScript, a truthy value is a value that translates to
true
when evaluated in a Boolean context. All values are truthy unless they are defined as falsy (i.e., except forfalse
,0
,""
,null
,undefined
, andNaN
).
entityMap => !!entityMap
将 entityMap
映射到规范的 bool 值,true
或 false
。另请参阅What is "!!" in C? .
如果 entityMap
具有 true 值,则 !entityMap
为 false
,并且 !!entityMap
为 true
。
如果 entityMap
具有假值,则 !entityMap
为 true
并且 !!entityMap
为 假
。
关于javascript - 这个箭头函数 JavaScript 代码是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38746936/