0
点赞
收藏
分享

微信扫一扫

箭头函数和普通函数的区别

穆熙沐 2022-04-01 阅读 111

1.箭头函数没有prototype属性

2.箭头函数的this指向定义时外层第一个普通函数的this

        不能直接修改箭头函数的this

        当箭头函数外层没有普通函数时,它的this在严格和非严格模式都是指向window。

3.箭头函数有外层函数时,arguments继承自外层函数的arguments,内部修改没用

        箭头函数没有外层函数直接使用arguments会报错

function foo() {
	console.log(arguments);//[Arguments] { '0': '外层1' }
	function boo () {
		console.log(arguments);//[Arguments] { '0': '外层2' }
		function coo () {
			console.log(arguments);//[Arguments] { '0': '最外层3' }
			let aoo = () => {
				console.log(arguments);//[Arguments] { '0': '最外层3' }!!!!!!!!
			}
			aoo('外层4');//没用!!!
		}
		coo('最外层3');
	}
	boo('外层2');
}
foo('外层1');

4.不能做构造函数,不能用new调用箭头函数

5.写法:

  1. 箭头函数不用写function
  2. 箭头函数只有一个参数时,可以省略括号
  3. 箭头函数可以省略{}和return
举报

相关推荐

0 条评论