箭头函数

  |  

箭头函数定义

采用 () => {} 的方式定义

箭头函数的特性

只能定义匿名函数

const a = () => {}

直接返回表达式或者结果时可以省略大括号

const a = () => 123

不能使用arguments, new, super关键字

const a = () => {super()} // error
const b = () => {console.log(arguments)} // error
const c = () =>{}
const d = new c() // error

没有原型对象

const c = () => {}
console.log(c.prototype) // undefined

没有自身的 this

箭头函数不会创建自己的this,它只会从自己的作用域链的上一层继承 this

const test =123
const a = {
test: 1,
getTest: () => {
console.log(this.test) // this 指向定义时的执行环境 this
// 这里的执行环境指
}
}

×

纯属好玩

扫码支持
扫码打赏,你说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

文章目录
  1. 1. 箭头函数定义
  2. 2. 箭头函数的特性
,