繁体   English   中英

函数或类之外的“超级”-react-native

[英]'super' outside of function or class - react-native

在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' outside of function or class错误'super' outside of function or class得到'super' outside of function or class

//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 在响应本机 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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM