【JavaScript】JavaScript基础-ES6新语法

小破孩
2022-06-21 / 0 评论 / 124 阅读 / 正在检测是否收录...
const 变量不变 let 变量可变
箭头函数,支持默认设置参数

    const fn=(a=1,b=2)=>{return a+b;}
    const fn1 = (a,b)=>a+b;  //简写,当返回值可省略括号

字符模板,不再使用+链接字符串

    const a = 20;
    const b = 30;
    const string = `${a}+${b}=${a+b}`;

解析结构

    const obj={
        a:1,
        b:2,
        c:3
    }
    const {a,b}=obj; 对象解析结构
    let  [a, b, c] = [1, 2, 3];数组的解析结构
    let [a, ...b] = [1, 2, 3]; 剩余运算 a=1 b=[2,3]

简写,当属性和值相同

    const person = { name, age,fn(){
    return   this.name;
    } }等价
    var person = {
      name: name,
      age: age
    ,
    fn:function fn(){
    return this.name;
    }
    };

类

    class Person {
    //构造方法
     constructor(name, age) { this.name = name; this.age = age; } 
    
    getName() { return this.name } 
    
    }

模块
接口定义可以是变量,函数,类

    var m=1
    export {m}
    export default默认方法或变量
    import {m} from 'm';
0

评论 (0)

取消