我正在尝试使用babel + es2015和es2016预设+ nodejs进行编译的简单程序,问题是ES2016没有编译代码并且显示与创建的类相同。
以下是index.js的示例代码
'use strict';
var express = require('express')
var MyArray = require('./myarray')
const square = new MyArray(10, 10);
console.log(square.area);
这是MyArray.js类文件:
class MyArray {
constructor(height, width) {
this.height = height;
this.width = width;
}
get area() {
return this.calcArea();
}
calcArea() {
return this.height * this.width;
}
}
当我使用ES2015进行编译时,这就是结果。
"use strict";
var _createClass = 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); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
/*
* @Author: Mandeep Singh Gill - thisismyaim@hotmail.com
* @Date: 2016-12-21 17:29:17
* @Last Modified by: mandeepgill
* @Last Modified time: 2016-12-22 12:07:26
*/
var MyArray = function () {
function MyArray(height, width) {
_classCallCheck(this, MyArray);
this.height = height;
this.width = width;
}
_createClass(MyArray, [{
key: "calcArea",
value: function calcArea() {
return this.height * this.width;
}
}, {
key: "area",
get: function get() {
return this.calcArea();
}
}]);
return MyArray;
}();
但是当我使用ES2016时,它在MyArray Build Directory中显示相同的MyArray.js代码没有改变原因?