10-3、对象展开运算符的应用

55 阅读1分钟
<script>
    // 1.复制对象
    // const a = { x: 1, y: 2 };
    // const b = a;

    // const c = { ...a };
    // console.log(c, c === a);

    // 2.用户参数和默认参数
    // add(1, 2);
    // const logUser = ({
    //     username = 'ZhangSan',
    //     age = 0,
    //     sex = 'male'
    // } = {}) => {
    //     console.log(username, age, sex);
    // };

    // const logUser = userParam => {
    //     const defaultParm = {
    //         username: 'ZhangSan',
    //         age: 0,
            // sex: 'male'
        // };
        // const param = { ...defaultParm, ...userParam }
        // const param = { ...defaultParm, ...undefined }
        // console.log(param.username);
        // const { username, age, sex } = { ...defaultParm, ...userParam };
        // console.log(username, age, sex);
    // };
    // logUser();
</script>