手记 babel

173 阅读1分钟

记录学习过程!

es6语法


	
class Person {
	constructor(){
      this.__attack = 100
    }
  	attcak(body){
      	body.blood -= this.__attack - body.defense;
    }
  	static say(){ //静态方法
    	console.log("hello")
    }
}

babel编译的结果

"use strict";

function _instanceof(left, right) {
    if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
        return !! right[Symbol.hasInstance](left);
    } else {
        return left instanceof right;
    }
}

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;
}

var Person =
/*#__PURE__*/
function() {
    function Person() {
        _classCallCheck(this, Person);

        this.__attack = 100;
    }

    _createClass(Person, [{
        key: "attcak",
        value: function attcak(body) {
            body.blood -= this.__attack - body.defense;
        }
    }], [{
        key: "say",
        value: function say() {
            console.log("hello");
        }
    }]);

    return Person;
} ();