zoukankan      html  css  js  c++  java
  • ES6模块化

    前言

    语法:import export (注意有无default)
    环境:babel编译ES6语法,模块化可用webpack 和rollup
    ES6 Class本身是个语法糖,实际系统默认帮我们转成JS的构造函数
     

    JS构造函数方式:

     
    class Hello(x,y){
    this.x=x;
    this.y=y;
    }
    Hello.protoype.add=function(){
    return this.x +this.y;
    }
    const m =new Hello(2,3);
    console.log(m.add()); // 5
    typeof Hello === "function" . //true
    Hello === Hello.prototype.constructor //true
    Hello.__proto__ === Hello.prototype //true
     

    ES6书写方式:

     
    export class Hello() {
    constructor(x,y){
    this.x = x;
    this.y = y;
    }
    add() {
    return this.x +this.y;
    }
    }
    const m =new Hello(2,3);
    console.log(m.add()); // 5
    typeof Hello === "function" . //true
    Hello === Hello.prototype.constructor //true
    Hello.__proto__ === Hello.prototype //true
    

      

  • 相关阅读:
    Junit单元测试
    Stream流方法引用
    Stream流思想和常用方法
    算法
    函数式接口
    Zookeeper理解
    GreenPlum学习之(Share-nothing)架构
    链表反转问题
    KMP算法的java实现
    KMP详解之二
  • 原文地址:https://www.cnblogs.com/fuGuy/p/9215725.html
Copyright © 2011-2022 走看看