箭头函数和普通函数的区别
作者:
9月的甜橙子 | 来源:发表于
2021-09-10 09:17 被阅读0次
- 箭头函数其实就是匿名函数,不可作为构造函数,不可被new;
- 箭头函数没有原型属性prototype;
- 箭头函数不绑定arguments,取而代之用rest参数...解决;
- 箭头函数里的this指向上下文,普通函数指向调用它的对象;
- 无论用什么办法都无法改变箭头函数的this指向,而普通函数可以通过call,apply,bind修改,具体见我的另一篇对比call,apply,bind
let f1 = () => {
console.log('我是箭头函数');
}
function f2(){
console.log('我是普通函数');
}
let f3 = (...c) => {
//箭头函数不绑定arguments,取而代之用rest参数...
console.log(c);
}
console.log(f1.prototype); // undefined
console.log(f2.prototype); // {constructor: ƒ}
如果本文对您有帮助,请给我点赞哦~ 谢谢~
本文标题:箭头函数和普通函数的区别
本文链接:https://www.haomeiwen.com/subject/qxqpwltx.html
网友评论