【发布时间】:2016-10-09 10:43:42
【问题描述】:
我尝试扩展代理,像这样:
class ObservableObject extends Proxy {}
我使用 Babel 将其转译为 ES5,但在浏览器中出现此错误:
app.js:15 Uncaught TypeError: Object prototype may only be an Object or null: undefined
我查看了它指向的代码行。这是代码的那部分,箭头指向有问题的代码行:
var ObservableObject = exports.ObservableObject = function (_Proxy) {
_inherits(ObservableObject, _Proxy); // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
function ObservableObject() {
_classCallCheck(this, ObservableObject);
return _possibleConstructorReturn(this, Object.getPrototypeOf(ObservableObject).apply(this, arguments));
}
return ObservableObject;
}(Proxy);
有谁知道我为什么会收到这个错误?这是 Babel 中的错误吗?当您尝试扩展 Proxy 时会发生什么?
【问题讨论】:
-
在 Firefox 中,这会抛出一个
undefined is not an object or null和一些ReferenceError: can't access lexical declaration [class name] before initialization。
标签: javascript ecmascript-6 babeljs es6-proxy