JavaScript-箭头函数
箭头函数兼容性
箭头函数定义
lambda 函数以尽量简洁的语法定义函数,是函数表达式的简化版。
1 | param => expression // 只有一个参数,省略括号,操作符,胖箭头 => 箭头函数的核心。仅一行语句,即为返回值。省略 { return expression } |
箭头函数与函数执行上下文
箭头函数没有单独的
this
, 箭头函数的this
与 函数声明所在的上下文相同,由以 demo 可知,因 箭头函数在 window 中定义,所以this
指向window
,函数表达式this
指向调用的环境,所以this
指向lambda
对象
1 | function thisLambda() { |