Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/448.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/35.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Extendend类在子方法和父方法之间移动_Javascript_Node.js - Fatal编程技术网

Javascript Extendend类在子方法和父方法之间移动

Javascript Extendend类在子方法和父方法之间移动,javascript,node.js,Javascript,Node.js,只是一个简单的问题 我扩展了一个类,它不是我的,我需要使用YamlDataSource中的一些函数 class PersistenceDataSource extends YamlDataSource { constructor() { super(); this._ = this; } 问题是:我需要使用一个只知道函数反弹的管理器,例如fetchAll 所以我需要在PersistenceDataSouce中使用它,但我还需要调用在YamlDa

只是一个简单的问题

我扩展了一个类,它不是我的,我需要使用YamlDataSource中的一些函数

class PersistenceDataSource extends YamlDataSource {
    constructor() {
        super();
        this._ = this;

    }
问题是:我需要使用一个只知道函数反弹的管理器,例如fetchAll

所以我需要在PersistenceDataSouce中使用它,但我还需要调用在YamlDataSouce中实现的那个

如果我这样做,PersistenceDataSource中的fetchAll函数将被激发,因此我想用我在构造函数中制作的解决方案来解决它,这是一个好的解决方案吗?

您可以使用super.METHOD,就像使用super调用构造函数一样

因此:

async fetchAll(config) {
    super.fetchAll(); // This will call the extended class fetchAll method (YamlDataSource fetchAll) instead of this class one.
});
async fetchAll(config) {
    super.fetchAll(); // This will call the extended class fetchAll method (YamlDataSource fetchAll) instead of this class one.
});