Skip to content

完整的解构赋值支持 #68

Description

@zqq90

目前已支持简单的数组赋值:

[a, b, c] = [1, 2, 3];

事实上 ES6 支持的 [模式匹配] 更为复杂

var [foo, [[bar], baz]] = [1, [[2], 3]];
foo // 1
bar // 2
baz // 3

var [ , , third] = ["foo", "bar", "baz"];
third // "baz"

var [x, , y] = [1, 2, 3];
x // 1
y // 3

var [head, ...tail] = [1, 2, 3, 4];
head // 1
tail // [2, 3, 4]

var [x, y, ...z] = ['a'];
x // "a"
y // undefined
z // []
let { foo, bar } = { foo: "aaa", bar: "bbb" };
foo // "aaa"
bar // "bbb"

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions