最近在项目中频繁的使用了箭头函数,在使用的过程中对return
关键字用法比较困惑,下面对其使用方法进行记录:
- 如果箭头函数的代码块部分多于一条语句,就要使用大括号将它们括起来,并且使用
return
关键字返回
const foo = (a, b) => {
a+b;
}
foo(1, 2) // undefined
const foo1 = (a, b) => {
return a+b;
}
foo1(1, 2) // 3
let fieldMeta = [
{
fieldCnName: 'aaaaa',
fieldDesc: 'string',
fieldLength: 'string',
fieldName: 'string',
fieldType: 'string',
primaryKey: false,
seq: 0
},
{
fieldCnName: 'bbbb',
fieldDesc: 'string',
fieldLength: 'string',
fieldName: 'string',
fieldType: 'string',
primaryKey: false,
seq: 0
},