簡體   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