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

es6 函数扩展

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

参数默认值

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://webge.net/?id=52

返回列表

上一篇:es6 数组扩展

下一篇:es6 Symbol

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

es6 作用域

作用域 let  constconst定义是常量不可修改,除引用外1,let声明的变量只有在块作用域是{}里可以访问,之外就不可访问2,使用let不可以重复定义变量3,代码用了es6是强制作用了严格模式的,在es5是开启严格模式“use strict”,在es6中不用这种话,4,在严格模式...

es6 解构的使用场景

二,解构{    let a,b,rest;    [a,b]=[1,2]    console.log(a,b);  // 1 2}{   ...

es6 数组扩展

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

es6 类

类的概念(基本语法,继承关系,静态方法,表态属性)类还提供了getter  setter{//基本定义和生成实例class Parent{constructor(name='mukewang'){this.name=name;}}}{//继承class Parent{con...

es6 解构函数默认值

es6 解构函数默认值

1,如果函数对数解构值有默认值的情况,调用传值参数不传不会报错2,如果出现解构值没有默认值,那当传参数的时候没有传就会报错...