title: Babel/RequireJS + typeof "RangeError: Maximum call stack size exceeded"
body: <p>I have a very basic JS error and I'm quite ashamed to not be able to solve it...</p>
  
  <p>I'm developping with ES6 and Babel and I'm making some experiments. 
  Please note I'm using these arguments with Babel:</p>
  
  <p><code>--presets es2015 --plugins transform-es2015-modules-amd</code></p>
  
  <p>I have a simple module:</p>
  
  <pre><code>"use strict";
  
  export default class Inspector {
      static inspect() {
          console.log(this.prototype.myMethod);
          console.log(typeof this.prototype.myMethod);
      }
  }
  </code></pre>
  
  <p>I use this module like that:</p>
  
  <pre><code>"use strict";
  
  import Inspector from "inspector";
  
  class Child extends Inspector {
      myMethod() {
          console.log(`Hello from ${this.name}`);
      }
  }
  
  Child.inspect();
  </code></pre>
  
  <p>The goal here is really dumb: simply check how the prototype is populated with ES6 inheritance.</p>
  
  <p>The first <code>console.log</code> from <code>inspect()</code> method displays, as expected:</p>
  
  <blockquote>
    <p>function myMethod() {
            console.log("Hello from " + this.name);
        }</p>
  </blockquote>
  
  <p>Inheritances has worked as expected, hourray!
  But the funny part is the second <code>console.log</code> (<code>console.log(typeof this.prototype.myMethod);</code>) which triggers an error:</p>
  
  <blockquote>
    <p>require.js:19 RangeError: Maximum call stack size exceeded(…)</p>
  </blockquote>
  
  <p>I was expecting something more like "function", but hey, I suppose I'm quite naive...</p>
  
  <p>This error seems to be related to requirejs modules, but I have no clues why I can log the function but not its type.</p>
  
  <p>Please also note that <strong>I can</strong> call this method in the <code>inspect</code> method:</p>
  
  <pre><code>static inspect() {
          this.prototype.myMethod();
  }
  </code></pre>
  
  <p>This displays "Hello from undefined" (I was expected "Hello from Child" but since it's not a static method, it's normal. Anyway, the call is correctly performed!).</p>
  
  <p>So, my question here: why can I log and call a method but I can't run <code>typeof</code> on it?</p>
  
  <p>Thanks in advance!</p>
  
  <p><strong>EDIT</strong>: you can see below the transpiled files:</p>
  
  <p><strong>inspector.js</strong></p>
  
  <pre><code>define(["exports"], function (exports) {
      "use strict";
  
      Object.defineProperty(exports, "__esModule", {
          value: true
      });
  
      function _typeof(obj) {
          return obj &amp;&amp; typeof Symbol !== "undefined" &amp;&amp; obj.constructor === Symbol ? "symbol" : typeof obj === "undefined" ? "undefined" : _typeof(obj);
      }
  
      function _classCallCheck(instance, Constructor) {
          if (!(instance instanceof Constructor)) {
              throw new TypeError("Cannot call a class as a function");
          }
      }
  
      var _createClass = (function () {
          function defineProperties(target, props) {
              for (var i = 0; i &lt; 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;
          };
      })();
  
      var Inspector = (function () {
          function Inspector() {
              _classCallCheck(this, Inspector);
          }
  
          _createClass(Inspector, null, [{
              key: "inspect",
              value: function inspect() {
                  this.prototype.myMethod();
                  console.log(this.prototype.myMethod);
                  console.log(_typeof(this.prototype.myMethod));
              }
          }]);
  
          return Inspector;
      })();
  
      exports.default = Inspector;
  });
  </code></pre>
  
  <p><strong>child.js</strong></p>
  
  <pre><code>function _typeof(obj) { return obj &amp;&amp; typeof Symbol !== "undefined" &amp;&amp; obj.constructor === Symbol ? "symbol" : typeof obj; }
  
  define(["inspector"], function (_inspector) {
      "use strict";
  
      var _inspector2 = _interopRequireDefault(_inspector);
  
      function _interopRequireDefault(obj) {
          return obj &amp;&amp; obj.__esModule ? obj : {
              default: obj
          };
      }
  
      function _classCallCheck(instance, Constructor) {
          if (!(instance instanceof Constructor)) {
              throw new TypeError("Cannot call a class as a function");
          }
      }
  
      var _createClass = (function () {
          function defineProperties(target, props) {
              for (var i = 0; i &lt; 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 _possibleConstructorReturn(self, call) {
          if (!self) {
              throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
          }
  
          return call &amp;&amp; ((typeof call === "undefined" ? "undefined" : _typeof(call)) === "object" || typeof call === "function") ? call : self;
      }
  
      function _inherits(subClass, superClass) {
          if (typeof superClass !== "function" &amp;&amp; superClass !== null) {
              throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
          }
  
          subClass.prototype = Object.create(superClass &amp;&amp; superClass.prototype, {
              constructor: {
                  value: subClass,
                  enumerable: false,
                  writable: true,
                  configurable: true
              }
          });
          if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass;
      }
  
      var Child = (function (_Inspector) {
          _inherits(Child, _Inspector);
  
          function Child() {
              _classCallCheck(this, Child);
  
              return _possibleConstructorReturn(this, Object.getPrototypeOf(Child).apply(this, arguments));
          }
  
          _createClass(Child, [{
              key: "myMethod",
              value: function myMethod() {
                  console.log("Hello from " + this.name);
              }
          }]);
  
          return Child;
      })(_inspector2.default);
  
      Child.inspect();
  });
  </code></pre>
  
  <p>Exception stracktrace is not very helpful unfortunately :</p>
  
  <blockquote>
    <p>ea.check  @   require.js:19</p>
    
    <p>(anonymous function)  @   require.js:23</p>
    
    <p>(anonymous function)  @   require.js:8</p>
    
    <p>(anonymous function)  @   require.js:24</p>
    
    <p>x @   require.js:7</p>
    
    <p>ea.emit   @   require.js:24</p>
    
    <p>ea.check  @   require.js:20 ea.enable @   require.js:24</p>
    
    <p>ea.init   @   require.js:17 J @   require.js:14</p>
    
    <p>h.completeLoad    @   require.js:29</p>
    
    <p>h.onScriptLoad @  require.js:30</p>
  </blockquote>
  
  <p><strong>EDIT2:</strong> By looking at the transpiled files, it seems that my <code>typeof</code> is replaced with method <code>_typeOf</code> from Babel. And this function is looping infinitely...</p>
  
  <p>Is it a bug with Babel? Did I miss any arguments for the compilation?</p>