立即函数使用es6返回不同类型的函数

时间:2018-04-11 08:15:42

标签: ecmascript-6 arrow-functions

const contains1 = (() => {
  debugger;
  Array.prototype.includes
    ? (arr, value) => arr.includes(value)
    : (arr, value) => arr.some(el => el === value)
})()

当我调用contains1时,它返回undefined。

const contains2 = (() => 
   Array.prototype.includes
    ? (arr, value) => arr.includes(value)
    : (arr, value) => arr.some(el => el === value)
)()

但是当我调用contains2时,它会返回一个函数。

为什么碰巧有不同的回报?

enter image description here

0 个答案:

没有答案
相关问题