东莞城乡住房建设厅网站,网页制作培训教程,赤峰网站设计,城乡住房和建设厅官网ref
1. 定义 函数 function getName() {}箭头函数 const getName () {}2. 命名 函数分为匿名、具名。 function getName() {}
let getName function () {}箭头函数只有匿名。 const getName () {}3. 构造函数
箭头函数都是匿名函数#xff0c;所以不能作为构造…ref
1. 定义 函数 function getName() {}箭头函数 const getName () {}2. 命名 函数分为匿名、具名。 function getName() {}
let getName function () {}箭头函数只有匿名。 const getName () {}3. 构造函数
箭头函数都是匿名函数所以不能作为构造函数。
使用箭头函数没有自己的词法上下文因此不会有作用域 this也不能用于构造函数。
let gen () {}
new gen()new gen() // VM82:4 Uncaught TypeError: gen is not a constructor at :4:10 ^ TypeError: gen is not a constructor 4. arguments
略
5. 原型对象 函数 function getName() {}
console.log(getName.prototype){} 箭头函数没有原型对象。 const getName () {}
console.log(getName.prototype)undefined
6. 简写方式
箭头函数返回一个对象时可以使用 () 包裹并省略 return。
const getKV () {return {age: 12}
}简化后
const getKV () ({age: 12})