Babel编译:类
编译前
class Fruit{
static nutrition = "vitamin"
static plant(){
console.log('种果树');
}
name;
constructor(name){
this.name = name;
}
hello(){
console.log(this.name);
}
}
编译后
"use strict"; // 是否是实例
function _instanceof(left, right) {
// 支持Symbol时,right可以是函数/对象:Symbol.hasInstance指向一个内部方法。
if (
right != null &&
typeof Symbol !== "undefined" &&
right[Symbol.hasInstance]
) {
return !!right[Symbol.hasInstance](left);
}
// 不支持Symbol时,right必须是函数
else {
return left instanceof right;
}
} // 必须通过new运算符,调用构造函数
function _classCallCheck(instance, Constructor) {
if (!_instanceof(instance, Constructor)) {
throw new TypeError("Cannot call a class as a function");
}
} // 添加一组成员方法
function _defineProperties(target, props) {
for (var i = 0; i < props.length; i++) {
var descriptor = props[i];
descriptor.enumerable = descriptor.enumerable || false;
descriptor.configurable = true;
if ("value" in descriptor) descriptor.writable = true;
Object.defineProperty(target, descriptor.key, descriptor);
}
} // 创建类
function _createClass(Constructor, protoProps, staticProps) {
// 类的实例方法:作为构造函数的原型的属性
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
// 类的静态方法:作为构造函数的属性
if (staticProps) _defineProperties(Constructor, staticProps);
return Constructor;
} // 添加一个属性
function _defineProperty(obj, key, value) {
if (key in obj) {
Object.defineProperty(obj, key, {
value: value,
enumerable: true,
configurable: true,
writable: true
});
} else {
obj[key] = value;
}
return obj;
} // 使用立即执行函数,创建类
var Fruit =
/*#__PURE__*/
(function () {
// 类的静态方法
_createClass(Fruit, null, [
{
key: "plant",
value: function plant() {
console.log("种果树");
}
}
]); // 类对应的构造函数
function Fruit(name) {
// 构造函数调用检查
_classCallCheck(this, Fruit); // 类的实例属性:作为new创建的上下文的属性
_defineProperty(this, "name", void 0); this.name = name;
} // 类的实例方法
_createClass(Fruit, [
{
key: "hello",
value: function hello() {
console.log(this.name);
}
}
]); return Fruit;
})(); // 类的静态属性:作为构造函数的属性
_defineProperty(Fruit, "nutrition", "vitamin");
Babel编译:类的更多相关文章
- KoaHub.js可借助 Babel 编译稳定运行在 Node.js 环境上
koahubjs KoaHub.js -- 基于 Koa.js 平台的 Node.js web 快速开发框架.可以直接在项目里使用 ES6/7(Generator Function, Class, A ...
- 使用babel编译es6
起因:开发中慢慢的学习使用es6,但是JavaScript需要浏览器来解析,而不是所有浏览器都支持es6,所以为了兼容es6,需要第三方工具进行编译es6. 工具:node,gulp,gulp-bab ...
- React系列文章:Babel编译JSX生成代码
上次我们总结了React代码构建后的Webpack模块组织关系,今天来介绍一下Babel编译JSX生成目标代码的一些规则,并且模拟整个生成的过程. 我们还是拿最简单的代码举例: import {gre ...
- webpack打包调试react并使用babel编译jsx配置方法
http://lxj8749.iteye.com/blog/2287074 ********************************************** 安装webpack npm i ...
- es6 babel编译
本文主要参照阮一峰的es6入门,为提高自己写了一份随笔. 原文地址请戳这里 ECMAScript 6 入门 ECMAScript 6是JavaScript语言的下一代标准.因为当前版本的ES6是在2 ...
- Eclipse - 安装了jd-eclipse插件后依然无法反编译类文件
问题 Eclipse在安装了jd-eclipse插件后依然无法反编译类文件,这个问题是因为没有修改默认的类文件查看器. 解决方法 修改默认的类文件查看器为jd-eclipse Window -> ...
- Babel编译:类继承
编译前 // 父类 class Fruit { static nutrition = "vitamin" static plant() { console.log('种果树'); ...
- java动态编译类文件并加载到内存中
如果你想在动态编译并加载了class后,能够用hibernate的数据访问接口以面向对象的方式来操作该class类,请参考这篇博文-http://www.cnblogs.com/anai/p/4270 ...
- intellij idea 热部署失效,需要手动编译类
从网上看到的解决方案,做一下备忘: spring boot项目中遇到jrebel类需要手动编译才会触发热部署的问题(spring boot devtools一样的问题) 1.ctl + shift + ...
随机推荐
- 移动端适配 后篇(rem+vm)
涉及到的一些名词, 详细解释可参考 移动端适配前篇--移动端适配 rem 名词解释 [英寸Inch]英寸表示屏幕斜对角线的长度 [像素Pixel]像素是图像的基本采样单位,它不是一个确定的物理量,因为 ...
- WPF 样式Style
一:样式基础 如果我们的程序有三个这样的按键,一般我们会这样写 <StackPanel> <!--按键的背景色为Azure蔚蓝色背景色为Coral珊瑚色字体为Arial加粗字体大小为 ...
- 【模板】Lucas定理
代码如下 #include <bits/stdc++.h> using namespace std; typedef long long LL; const int maxn=1e5+10 ...
- Eclipse中对一个项目进行复制粘贴为一个新项目
1:对目标项目执行右键,选择“Copy”,然后在空白处右键,选择“Paste”结果如下图: 2:右键新项目,点击Properties, 3:打开Navigator视图 4:打开.settings文件夹 ...
- jq实现表格多行列复制
<!DOCTYPE html><html><head> <meta charset="utf-8"> <title>&l ...
- wordpress在线预览pdf插件
插件名称:PDF.js Viewer Shortcode 插件主页:http://tphsfalconer.com/ 优点:功能强大,有分页缩略图功能,翻页,放大缩小,打印,下载,读取等功能. 使用方 ...
- CSS布局之flexbox
参考链接: https://www.cnblogs.com/qingchunshiguang/p/8011103.html 练习代码 <!DOCTYPE html> <html la ...
- 在线PDF的实现 纯js
/// <summary> /// 使用微软的TransmitFile下载文件 /// </summary> /// <param name="filePath ...
- web项目重启命令
jps -lvm|grep "young_rd_10004" | awk '{print $1}'|xargs kill -9; sleep 3; /home/web_server ...
- Django之nginx+wsgi后台部署(最新版)
0-部署准备 1.要使用安全组打开腾讯云的80端口 腾讯云的80端口不能访问www.jianshu.com 以实际项目部署为例 项目名称api_learn: Python版本:python 3.6. ...