首页 > 其他 > 详细

ES6模块化

时间:2018-06-22 23:06:34      阅读:173      评论:0      收藏:0      [点我收藏+]

前言

语法: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

  

ES6模块化

原文:https://www.cnblogs.com/fuGuy/p/9215725.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!