当前位置:首页 > ES6 > 正文内容

es6 函数扩展

自由小鸟6年前 (2019-07-26)ES62879

参数默认值

rest参数

扩展运算符

箭头函数

this绑定

尾调用


// 参数默认值

{

    function test(x,y='world'){

        console.log('默认值',x,y)

    }

    test('hello');

    test('hello','kill')

}

// 作用域

{

    let x='test'

    function test2(x,y=x){

        console.log('作用域',x,y)

    }

    test2('kill');

}


// 

{

    function test3(...arg){

       for(let v of arg){

            console.log('rest',v)  

        }

    }

    test3(1,2,3,4,'a');

}

{

    console.log(...[1,2,3])  //1 2 3 把数组分成离散的值

}


箭头函数

1, = 前面就是函数名  

2, =>这个符号前是函数参数 ,如果没有参数就用()代替

3,后面就是函数内容

4,做箭头函数时注意绑定

{

    let arrow = v =>v*2      

    let arrow

}


伪调用 ,//在不断的调用嵌套调用可以用

{

    function tail(x){

        console.log('tauk',x);

    }

    function fx(x){

        return tail(x)

    }

    fx(123)

}


版权声明:本文由Web学习之路发布,如需转载请注明出处。

本文链接:https://www.webge.net/?id=52

返回列表

上一篇:es6 数组扩展

下一篇:es6 Symbol

“es6 函数扩展” 的相关文章

es6 数组扩展

Array.fromArray.ofcopyWithinfind/findindexfillentries/keys/valuesinludes{    let arr=Array.of(3,4,7,9,11)   //把一组数据变量转换成...

es6 语法

es6 语法

数据结构set的用法    weakSet的用法   Map的用法   weakMap的用法set用法{    let list=new Set()    li...

es6 promise

es6 promise

Promise是为解决什么问题而产生的?promise是为解决异步处理回调金字塔问题而产生的Promise的两个特点1、Promise对象的状态不受外界影响1)pending 初始状态2)resolve 成功状态3)reject 失败状态Promise 有以上三种状态,只有异步操作的结果可以决定当前...