Skip to content

常用的ES6特性 #4

@coffeexy

Description

@coffeexy
  • let
  • const
  • 解构赋值
let { id, status, data: number } = jsonData;// 对象的解构
[a, b] = [b, a]; // 交换变量的值
  • 设置参数默认值,且可以通过参数默认值强制要求传参
function mandatory() {
    throw new Error("Missing parameter");
}
function foo(mustBeProvided = mandatory()) {
    return mustBeProvided;
}
  • 模版字符串两个反引号,${}用来添加变量
  • 使用扩展运算符...拷贝数组。
const itemsCopy = [...items];
const nodes = Array.from(foo); //等同于👇
const nodes = Array.prototype.slice().call(foo);
  • 箭头函数(没有自己的thisarguments
  • 模块化importexport
export default es6;

......

import {firstName, lastName, year} from './profile';
  • Class
  • Promise

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions