谁能解释下面程序中的javascript代码?

时间:2020-08-15 07:16:05

标签: javascript

starMap={
  B: 'COM',
  C: 'B',
  D: 'C',
  E: 'D',
  F: 'E',
  G: 'B',
  H: 'G',
  I: 'D',
  J: 'E',
  K: 'J',
  L: 'K',
  YOU: 'K',
  SAN: 'I'
};
const getAncestors = body => body in starMap ? [ ...getAncestors(starMap[body]), starMap[body] ] : [];
console.log(getAncestors("YOU"));

const getAncestors = body => starMap中的body? [... getAncestors(starMap [body]),starMap [body]]:[];

我会理解,除了getancestor(starrmap [body])之外,所有期望都有额外的starmap [body]

1 个答案:

答案 0 :(得分:1)

starMap是对象getAncestors是一个函数,如果参数body在对象starMap中,则返回true。运算符的意思是这样的

let tog = 1 == 1 ? 'Yeah it is' : 'Nope'

相同

if(1==1){
  let tog = 'Yeah it is'
}
else {
  let tog = 'Nope'
}

getAncestors = body => body in starMap

const getAncestors = (body) => {
  return body in starMap;  //true or false
}