zoukankan      html  css  js  c++  java
  • 函数参数的解构赋值

    1、函数参数的解构赋值

                //函数参数的解构赋值
                
                function swap([x,y]){
                    return [y,x];
                };
                let arr = [1,2];
                arr = swap(arr);

    2、对象的解构赋值

                //对象的解构赋值
                function Computer({
                    cpu,
                    memory,
                    software = ['ie6'],
                    OS = 'windows 3.5'
                }){
                    console.log(cpu);
                    console.log(memory);
                    console.log(software);
                    console.log(OS);
                };
                
                new Computer({
                    memory:'128G',
                    cpu:'80286',
                    OS:'windows 10'
                })

    3、小案例实现

                //小案例实现
                function getUserInfo({
                    name,
                    sex = '女',
                    age,
                    height = '160cm'
                }){
                    console.log(name);
                    console.log(sex);
                    console.log(age);
                    console.log(height);
                    
                };
                getUserInfo({
                    name:'小花',
                    age:'23',
                    height:'158cm'
                })
  • 相关阅读:
    Doing Homework 简单dp&&状态压缩
    嫖裤子序列
    王宁宁宁
    友军寻路法
    Viviani
    ccf 201909-3
    ccf 201909-5
    链式前向星
    ccf-201909-04
    ccf -201909-2
  • 原文地址:https://www.cnblogs.com/rickdiculous/p/13122254.html
Copyright © 2011-2022 走看看