• es6基础入门变量的解构赋值


    1 let [a, b, c] = [1, 2, 3];
     1 let [foo, [[bar], baz]] = [1, [[2], 3]];
     2 foo // 1
     3 bar // 2
     4 baz // 3
     5 
     6 let [ , , third] = ["foo", "bar", "baz"];
     7 third // "baz"
     8 
     9 let [x, , y] = [1, 2, 3];
    10 x // 1
    11 y // 3
    12 
    13 let [head, ...tail] = [1, 2, 3, 4];
    14 head // 1
    15 tail // [2, 3, 4]
    16 
    17 let [x, y, ...z] = ['a'];
    18 x // "a"
    19 y // undefined
    20 z // []
    1 // 报错
    2 let [foo] = 1;
    3 let [foo] = false;
    4 let [foo] = NaN;
    5 let [foo] = undefined;
    6 let [foo] = null;
    7 let [foo] = {};
    1 let [x, y, z] = new Set(['a', 'b', 'c']);
    2 x // "a"
    1 let [foo = true] = [];
    2 foo // true
    3 
    4 let [x, y = 'b'] = ['a']; // x='a', y='b'
    5 let [x, y = 'b'] = ['a', undefined]; // x='a', y='b'
    1 let [x = 1] = [undefined];
    2 x // 1
    3 
    4 let [x = 1] = [null];
    5 x // null
    1 let [x = 1, y = x] = [];     // x=1; y=1
    2 let [x = 1, y = x] = [2];    // x=2; y=2
    3 let [x = 1, y = x] = [1, 2]; // x=1; y=2
    4 let [x = y, y = 1] = [];     // ReferenceError
    1 let { foo, bar } = { foo: "aaa", bar: "bbb" };
    2 foo // "aaa"
    3 bar // "bbb"
    1 let { bar, foo } = { foo: "aaa", bar: "bbb" };
    2 foo // "aaa"
    3 bar // "bbb"
    4 
    5 let { baz } = { foo: "aaa", bar: "bbb" };
    6 baz // undefined
    1 var { foo: baz } = { foo: 'aaa', bar: 'bbb' };
    2 baz // "aaa"
    3 
    4 let obj = { first: 'hello', last: 'world' };
    5 let { first: f, last: l } = obj;
    6 f // 'hello'
    7 l // 'world'
    1 let { foo: baz } = { foo: "aaa", bar: "bbb" };
    2 baz // "aaa"
    3 foo // error: foo is not defined
  • 相关阅读:
    微信接龙转Excel
    Nginx日志拆分(linux环境下)
    Nginx 安全设置(禁止Iframe跨域访问、隐藏server、限制ip访问)
    Nginx开机启动(Linux环境下)
    Navicat Premium 16激活教程(NavicatCracker)
    Tomcat日志拆分(linux)
    mysql 事务
    mysql 5.7数据类型支持json格式
    mysql 用户 权限管理
    mysql 读写锁(表锁myisam行锁innodb)
  • 原文地址:https://www.cnblogs.com/shuaihan/p/7218671.html
Copyright © 2020-2023  润新知