Javascript 巴别塔/RequireJS+;“类型”;RangeError:超过最大调用堆栈大小;

Javascript 巴别塔/RequireJS+;“类型”;RangeError:超过最大调用堆栈大小;,javascript,requirejs,ecmascript-6,babeljs,typeof,Javascript,Requirejs,Ecmascript 6,Babeljs,Typeof,我有一个非常基本的JS错误,我很惭愧不能解决它 我正在用ES6和Babel开发,我正在做一些实验。 请注意,我将这些参数用于Babel: --预设es2015--插件转换-es2015-modules-amd 我有一个简单的模块: "use strict"; export default class Inspector { static inspect() { console.log(this.prototype.myMethod); console.l

我有一个非常基本的JS错误,我很惭愧不能解决它

我正在用ES6和Babel开发,我正在做一些实验。 请注意,我将这些参数用于Babel:

--预设es2015--插件转换-es2015-modules-amd

我有一个简单的模块:

"use strict";

export default class Inspector {
    static inspect() {
        console.log(this.prototype.myMethod);
        console.log(typeof this.prototype.myMethod);
    }
}
我是这样使用这个模块的:

"use strict";

import Inspector from "inspector";

class Child extends Inspector {
    myMethod() {
        console.log(`Hello from ${this.name}`);
    }
}

Child.inspect();
这里的目标非常愚蠢:只需检查原型是如何用ES6继承填充的

第一个
console.log
来自
inspect()
方法,如预期的那样显示:

函数myMethod(){ log(“Hello from”+this.name); }

霍瑞,继承的工作和预期的一样! 但有趣的是第二个
console.log
console.log(typeof this.prototype.myMethod);
)触发了一个错误:

require.js:19 RangeError:超过最大调用堆栈大小(…)

我期待着更像“函数”的东西,但嘿,我想我很天真

这个错误似乎与requirejs模块有关,但我不知道为什么我可以记录函数而不是它的类型

还请注意,我可以在
inspect
方法中调用此方法:

static inspect() {
        this.prototype.myMethod();
}
这将显示“Hello from undefined”(我本来希望是“Hello from Child”,但由于它不是静态方法,所以这是正常的。无论如何,调用是正确执行的!)

所以,我这里的问题是:为什么我可以记录并调用一个方法,但我不能在它上运行
typeof

提前谢谢

编辑:您可以在下面看到传输的文件:

inspector.js

define(["exports"], function (exports) {
    "use strict";

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

    function _typeof(obj) {
        return obj && typeof Symbol !== "undefined" && 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 < 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;
});
function _typeof(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }

define(["inspector"], function (_inspector) {
    "use strict";

    var _inspector2 = _interopRequireDefault(_inspector);

    function _interopRequireDefault(obj) {
        return obj && 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 < 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 && ((typeof call === "undefined" ? "undefined" : _typeof(call)) === "object" || typeof call === "function") ? call : self;
    }

    function _inherits(subClass, superClass) {
        if (typeof superClass !== "function" && superClass !== null) {
            throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
        }

        subClass.prototype = Object.create(superClass && 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();
});
define([“导出”],函数(导出){
“严格使用”;
Object.defineProperty(导出,“\uu esModule”{
值:true
});
功能类型(obj){
返回obj&&typeof Symbol!=“未定义”&&obj.constructor==Symbol?“Symbol”:obj的类型==“未定义”?“未定义”:(obj)的类型;
}
函数_classCallCheck(实例、构造函数){
if(!(构造函数的实例实例)){
抛出新的TypeError(“无法将类作为函数调用”);
}
}
var_createClass=(函数(){
功能定义属性(目标、道具){
对于(变量i=0;i
child.js

define(["exports"], function (exports) {
    "use strict";

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

    function _typeof(obj) {
        return obj && typeof Symbol !== "undefined" && 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 < 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;
});
function _typeof(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }

define(["inspector"], function (_inspector) {
    "use strict";

    var _inspector2 = _interopRequireDefault(_inspector);

    function _interopRequireDefault(obj) {
        return obj && 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 < 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 && ((typeof call === "undefined" ? "undefined" : _typeof(call)) === "object" || typeof call === "function") ? call : self;
    }

    function _inherits(subClass, superClass) {
        if (typeof superClass !== "function" && superClass !== null) {
            throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
        }

        subClass.prototype = Object.create(superClass && 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();
});
函数_typeof(obj){return obj&&typeof Symbol!==“undefined”&&obj.constructor==Symbol?”Symbol:typeof obj;}
定义([“inspector”]、函数(_inspector){
“严格使用”;
var _inspector2=_InterprequiredFault(_inspector);
功能_互请求故障(obj){
返回对象和对象。返回模块?对象:{
默认值:obj
};
}
函数_classCallCheck(实例、构造函数){
if(!(构造函数的实例实例)){
抛出新的TypeError(“无法将类作为函数调用”);
}
}
var_createClass=(函数(){
功能定义属性(目标、道具){
对于(变量i=0;i