手记

函数扩展

es6新特性函数扩展

1.函数默认值

function show(a,b=8){  returna+b;}

2.箭头函数(给我的感觉就像是java中的lambda表达式)

var show= (a,b=7) => a+b;var show  = (a,b=7) => {  ...}

3.箭头函数中的this

setTimeout(function(){console.log(this)}),1)

这个函数中this表示的window

而箭头函数中的this始终指向函数定义时的this

setTimeout(()=>{console.log(this)},1);

这个函数中this表示函数外部的对象


0人推荐
随时随地看视频
慕课网APP