ES6 函数扩展笔记

 {
        //函数的新增特性
        // 参数默认值 rest参数 扩展运算符 箭头函数 this绑定 尾调用 

        function test(x,y='world'){//参数默认值 如果没有第二个参数 就拿默认参数
            console.log('默认值',x,y)
        }
        test('hello')
        test('hello','xiaohao')
    }
    {
        let x = 'test';//参数默认值
        function test2(x,y=x){//如果参数中有声明变量 参数读取参数值 如果没有则读取变量值
            console.log('作用域',x,y)
        }
        test2('xiaohao')
    }

    {
        function test3(...arg){ //arguments对象不是数组,只是可以下标访问而已,而rest参数是一个真正的数组。
            console.log(typeof arg)//rest参数,形式为:...变量名
            for(let i of arg){
                console.log('rest',i)
            }
        }
        test3(1,2,3,5,6,7,8,9)
    }
    {
        console.log(...[1,2,3,4,5,6])//扩展运算符为rest参数的逆用法 把数组转为零散的值
        console.log('a','b',...[1,2,3,4,5,6])
    }

    {//箭头函数
        let fun1 = ()=>{return 5} 
        console.log(fun1())

        let fun = v => v*2 //左边为函数名 中间v为参数 右边为函数体 没有参数为括号
        console.log(fun(6))
    }
    {   //尾调用写法 某个函数的最后一步是调用另一个函数 参考阮大神解释 
        function a(x){
            console.log(x)
        }
        function b(x){
            return a(x)
        }
        b('xiaohao')
    }

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值