Menu icon Foundation
How to import class using ES6 syntax?

Copied from babeljs.io

js/skin.js

'use strict';

class SkinnedMesh {
  constructor(geometry, materials) {
    this.idMatrix = SkinnedMesh.defaultMatrix();
    this.bones = [];
    this.boneMatrices = [];
    //...
  }
  update(camera) {
    //...
    console.log(camera);
  }
  static defaultMatrix() {
    return 0;
  }
}

export default SkinnedMesh;

 

js/import.js

 

 'use strict';

 import SkinnedMesh from './skin.js';

 let example = new SkinnedMesh(0, "2");
 example.update("kk");

 

Error in console of Google Chrome:

Uncaught ReferenceError: exports is not defined

'use strict';

Object.defineProperty(exports, "__esModule", {
  value: true
});

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

var SkinnedMesh = function () {
  function SkinnedMesh(geometry, materials) {
    _classCallCheck(this, SkinnedMesh);

    this.idMatrix = SkinnedMesh.defaultMatrix();
    this.bones = [];
    this.boneMatrices = [];
    //...
  }

  _createClass(SkinnedMesh, [{
    key: 'update',
    value: function update(camera) {
      //...
      console.log(camera);
    }
  }], [{
    key: 'defaultMatrix',
    value: function defaultMatrix() {
      return 0;
    }
  }]);

  return SkinnedMesh;
}();

exports.default = SkinnedMesh;

 

Uncaught ReferenceError: require is not defined

'use strict';

var _skin = require('../core/skin.js');

var _skin2 = _interopRequireDefault(_skin);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

var prueba = new _skin2.default(0, "2");
prueba.update("kk");

 

Thanks

 

 

 

Babeljavascript

Copied from babeljs.io

js/skin.js

'use strict';

class SkinnedMesh {
  constructor(geometry, materials) {
    this.idMatrix = SkinnedMesh.defaultMatrix();
    this.bones = [];
    this.boneMatrices = [];
    //...
  }
  update(camera) {
    //...
    console.log(camera);
  }
  static defaultMatrix() {
    return 0;
  }
}

export default SkinnedMesh;

 

js/import.js

 

 'use strict';

 import SkinnedMesh from './skin.js';

 let example = new SkinnedMesh(0, "2");
 example.update("kk");

 

Error in console of Google Chrome:

Uncaught ReferenceError: exports is not defined

'use strict';

Object.defineProperty(exports, "__esModule", {
  value: true
});

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

var SkinnedMesh = function () {
  function SkinnedMesh(geometry, materials) {
    _classCallCheck(this, SkinnedMesh);

    this.idMatrix = SkinnedMesh.defaultMatrix();
    this.bones = [];
    this.boneMatrices = [];
    //...
  }

  _createClass(SkinnedMesh, [{
    key: 'update',
    value: function update(camera) {
      //...
      console.log(camera);
    }
  }], [{
    key: 'defaultMatrix',
    value: function defaultMatrix() {
      return 0;
    }
  }]);

  return SkinnedMesh;
}();

exports.default = SkinnedMesh;

 

Uncaught ReferenceError: require is not defined

'use strict';

var _skin = require('../core/skin.js');

var _skin2 = _interopRequireDefault(_skin);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

var prueba = new _skin2.default(0, "2");
prueba.update("kk");

 

Thanks