xgqfrms™, xgqfrms® : xgqfrms's offical website of cnblogs! xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!

js function All In One

js function All In One

js ES5 Function & js Arrow Function

Object vs Array

花括号 ?对象 ❌, 傻傻分不清


// array OK
const arrFunc = () => [];
// () => []
arrFunc();
// []

const objFunc = () => {};
// () => {}
objFunc();
// undefined

大括号 & 优先级 ✅


// array OK
const arrFunc = () => ([]);
// () => ([])
arrFunc();
// []

const objFunc = () => ({});
// () => ({})
objFunc();
// {}

ES5 function

function objFunc () {};
// undefined
objFunc();
// undefined

function objFunc () {
 {};
 return;
};
// undefined
objFunc();
// undefined


function objFunc () {
  return {};
};
// undefined
objFunc();
// {}

refs

https://github.com/lydiahallie/javascript-questions/issues/220

https://mariusschulz.com/blog/returning-object-literals-from-arrow-functions-in-javascript



©xgqfrms 2012-2020

www.cnblogs.com 发布文章使用:只允许注册用户才可以访问!

原创文章,版权所有©️xgqfrms, 禁止转载 🈲️,侵权必究⚠️!


posted @ 2021-02-07 10:59  xgqfrms  阅读(73)  评论(3编辑  收藏  举报