• JS ****************


    let [x, [y, z]] = ['hello', ['JavaScript', 'ES6']];
    x; // 'hello'
    y; // 'JavaScript'
    z; // 'ES6'
    

    let [, , z] = ['hello', 'JavaScript', 'ES6']; // 忽略前两个元素,只对z赋值第三个元素 z; // 'ES6' var person = { name: '小明', age: 20, gender: 'male', passport: 'G-12345678', school: 'No.4 middle school', address: { city: 'Beijing', street: 'No.1 Road', zipcode: '100001' } }; var {name, address: {city, zip}} = person; name; // '小明' city; // 'Beijing' zip; // undefined, 因为属性名是zipcode而不是zip // 注意: address不是变量,而是为了让city和zip获得嵌套的address对象的属性: address; // Uncaught ReferenceError: address is not defined
    var person = { name: '小明', age: 20, gender: 'male', passport: 'G-12345678', school: 'No.4 middle school' };
    // 把passport属性赋值给变量id: let {name, passport:id} = person; name; // '小明' id; // 'G-12345678' // 注意: passport不是变量,而是为了让变量id获得passport属性: passport; // Uncaught ReferenceError: passport is not defined
    var person = { name: '小明', age: 20, gender: 'male', passport: 'G-12345678' };
    // 如果person对象没有single属性,默认赋值为true: var {name, single=true} = person; name; // '小明' single; // true var x=1, y=2; [x, y] = [y, x]

    apply、call

    function getAge() {
        var y = new Date().getFullYear();
        return y - this.birth;
    }
    
    var xiaoming = {
        name: '小明',
        birth: 1995,
        age: getAge
    };
    
    xiaoming.age(); // 25
    getAge.apply(xiaoming, []); // 25, this指向xiaoming, 参数为空
    getAge.call(xiaoming);

    .

  • 相关阅读:
    《构建之法》阅读笔记02
    《构建之法》阅读笔记01
    学习进度
    “校园知网”端午假期冲刺计划书
    学习进度
    计算最长英语单词链
    第一周冲刺_周日总结
    构建之法阅读笔记03
    第一周冲刺_周六总结
    软件工程概论第十四周学习进度
  • 原文地址:https://www.cnblogs.com/xiangsj/p/12361249.html
Copyright © 2020-2023  润新知