Before compilation
class Fruit{ static nutrition = "vitamin" static plant(){ console.log('种果树'); } name; constructor(name){ this.name = name; } hello(){ console.log(this.name); } }
Compiled
"use strict" ; // is an instance of function _instanceof (left, right) { // when supporting Symbol, right may be a function / object: Symbol.hasInstance points to an internal method. IF ( right ! = null && typeof ! the Symbol == "undefined" && right [Symbol.hasInstance] ) { return !! right [Symbol.hasInstance] (left); } // not supported Symbol, right must be a function else { return left the instanceof right; } } // be the new operator, call the constructor 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" indescriptor) = descriptor.writable to true ; ; Object.defineProperty (target, descriptor.key, descriptor) } } // Create a class function _createClass (the Constructor, protoProps, staticProps) { // instance method of class: the prototype is added to the constructor IF (protoProps) _defineProperties (Constructor.prototype, protoProps); // static methods class: Add to the constructor IF (staticProps) _defineProperties (the constructor, staticProps); return the constructor; } // add an attribute function _defineProperty (obj, Key, value) { IF (Key in obj) { Object.defineProperty (obj, Key, { value: value, Enumerable: to true , Configurable: to true , Writable: to true }); } the else { obj [Key] = value; } return obj; } // immediately execute the function, creates class var Fruit = / * #__PURE__ * / ( function () { // static methods of a class _createClass (Fruit, null , [ { Key:"Plant" , value: function Plant () { the console.log ( "Fruit Species" ); } } ]); // corresponding to a class constructor function Fruit (name) { // constructor calls check _classCallCheck ( the this , Fruit ); // class instance attributes _defineProperty ( the this , "name", void 0 ); the this .name = name; } // instance method of class _createClass (Fruit, [ { Key: "Hello", value: function hello() { console.log(this.name); } } ]); return Fruit; })(); // 类的静态属性 _defineProperty(Fruit, "nutrition", "vitamin");