Open otakustay opened 9 years ago
箭头函数的特点是:
建议如下:
function foo() {}
this
property descriptor
get
set
bind
参数一定要用括号,哪怕只有一个参数
只有一个语句的函数不换行且不写return且不加大括号:
ajax(url).then((result) => console.log(result)); array.map((item) => item.name);
避免多个箭头函数嵌套,看得眼疼
http://stackoverflow.com/questions/22939130/when-should-i-use-arrow-functions-in-ecmascript-6
说下我的建议:
function
函数语法选择
箭头函数的特点是:
建议如下:
function foo() {}
,不要用箭头函数,这里用不了this
this
或this
不是当前词法this
的,使用function foo() {}
,典型的就是声明一个property descriptor
里的get
和set
,this
是依赖执行时给定的。不过尽量避免变this
的函数出现function foo() {}
,别蛋疼用去Y因子做这事,你不累看的人累bind
了箭头函数
参数一定要用括号,哪怕只有一个参数
只有一个语句的函数不换行且不写return且不加大括号:
避免多个箭头函数嵌套,看得眼疼