我有2类:MyClass和CBook。我想从CBook类访问MyClass类的所有函数和变量。我怎样才能做到这一点 ?

我的课

import $ from 'jquery';
import {CBook} from './book';

const path = "http://www.mypage.com";

class MyClass {

    constructor() {
        let _summaryPageUI = new CBook(this);
    }

    describeBook() {
        console.log('test');
    }

}

new MyClass();

export {MyClass};


我想从CBook中的MyClass访问所有方法:

CBook

class CBook {
    constructor(myClass) {
        console.log(myClass);
    }
}

export {CBook};

最佳答案

我认为您正在寻找extends属性。请参阅以下文档:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes/extends

要么
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes

class myClass extends CBook {
  ....
}

07-28 07:44