2016-08-03 101 views
0

我想了解HomeAssistant前端源代码。我发现我不明白的函数定义。我不明白这句法(model.entity是一个字符串)...这个箭头函数代码是什么意思?

export function createHasDataGetter(model) { 
    return [ 
    ['restApiCache', model.entity], 
    entityMap => !!entityMap, 
    ]; 
} 

看起来像水木清华:

return [[string, string], bool]

什么是这个函数的exacly teturn类型?这只是布尔?如果是,是否意味着entityMap是字符串数组?

+0

如果您已经知道这是一个箭头功能,您对此感到困惑吗?好像你已经知道这是一个函数而不是'bool'。 – 2016-08-03 14:52:59

+0

Duplicate of:http://stackoverflow.com/questions/24900875/whats-the-meaning-of-an-arrow-formed-from-equals-greater-than-in-javas?noredirect=1&lq=1 – Paulpro

+0

'entityMap => !! entityMap'相当于'function(entityMap){return !! entityMap; }' – Paulpro

回答

3

参见"Truthy" on MDN

在JavaScript中,一个truthy值是在一个布尔上下文中计算时,转换到true的值。除非它们被定义为伪造(除了false0,"",nullundefinedNaN),所有的值都是真值。

entityMap => !!entityMapentityMap映射到规范布尔值,truefalse。另见What is "!!" in C?

如果entityMap具有truthy值,则!entityMapfalse,和!!entityMaptrue

如果entityMap具有falsy值,则!entityMaptrue!!entityMapfalse