2016-08-03 125 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