函数返回对象写法的失误

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_24147051/article/details/81317087

下面两个函数是不等价的

foo1 = () =>
{
  return {
      bar: "hello"
  };
}

foo2 = () =>
{
  return
  {
      bar: "hello"
  };
}

console.log(foo1());      // {bar : "hellp"}
console.log(foo2());    // undefined

效果:

这里写图片描述


猜你喜欢

转载自blog.csdn.net/qq_24147051/article/details/81317087