在react-native中工作,我有一大块在不同地方演示过的代码(例如 https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/super )
let Vehicle = {
debug() {
return 'Vehicle';
}
};
let Car = {
debug() {
return super.debug() + ' is a Car';
}
};
无论我如何实例化 Car,我都会收到'super'超出函数或类
错误:
//set prototype on object
Object.setPrototypeOf(Car, Vehicle);
Car.debug(); //error
//create instance
let c = Object.create(Car);
//set prototype on instance
Object.setPrototypeOf(c, Vehicle);
c.debug(); //error
为什么会抛出此错误以及如何使用对象调用 super
?
最佳答案
似乎 setPrototypeOf 在 React Native 中没有兼容 https://facebook.github.io/react-native/docs/javascript-environment.html 。在这里我没有看到 Object.setPrototypeOf 的 babel 插件 https://github.com/facebook/react-native/blob/master/babel-preset/configs/main.js#L16 .
关于javascript - 函数或类之外的“ super ”-react-native,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41923501/