我在导出原型类时似乎遇到了问题。
举个例子:
/* eslint no-shadow:0 */
var UtilityManager = (function(w, d, c) {
function UtilityManager() {
c.log('UtilityManager created!');
}
UtilityManager.prototype.extendObject = function(base, extending) {
var key;
if (typeof extending !== 'object') {
c.warn('Extending object is not of type Object');
extending = {};
}
for (key in extending) {
if (Object.hasOwnProperty.call(base, key)) {
base[key] = extending[key];
}
}
return base;
};
return UtilityManager;
}(window, document, console));
export default UtilityManager;
当我尝试使用
访问此代码时UtilityManager = require('./helpers/dfp.utility');
UtilityManager = new UtilityManager();
首先,我希望这会奏效:
UtilityManager = new (require('./helpers/dfp.utility'))();
不幸的是,它没有。欢迎解释:) 无论如何,当运行代码时,我收到以下错误消息:
未捕获的TypeError:UtilityManager不是构造函数
怎么回事?