let a = () => {}
可省略
(),多个的话不能省略
(),用 ,号分开let a = m => {}
let b = (m, n) => {}
let a = () => 1
// console.log(a()) 值为1
let a = () => 1
let b = new a()
Uncaught TypeError: a is not a constructor
at <anonymous>:3:9
let people = {
name: 'xiaoming',
fn: () => {
console.log(this.name) // 没有返回值
console.log(this, '箭头函数的 this 的执行环境') // window
},
fn2: function () {
console.log(this.name) // xiaoming
console.log(this, '普通函数 this 的执行环境') // 当前对象 test
}
}
people.fn()
people.fn2()
结果:
let a = () => 1
let b = function () {
return 1
}
console.log(a.prototype); // undefined
console.log(b.prototype); // {constructor: ƒ}
// 报错
let a = (m) => {
console.log(arguments)
}
a(1,2,3) // arguments is not defined
// 值是有外围非箭头函数所决定的
function fn(){
let f = ()=> {
console.log(arguments)
}
f();
}
fn(1,2,3) // [1,2,3]
// 普通函数的 arguments
let b = function () {
console.log(...arguments)
}
b(1,2,3) // 1,2,3
当然箭头函数与普通函数的区别还有很多,小编总结的也不是很齐全,有想法的,请各位看官大大多多交流指正~~