JavaScript ES6 - 为超级分配方法

时间:2017-04-01 00:51:54

标签: javascript class ecmascript-6 super assign

我目前正在尝试找出一种方法将方法分配给类中的超级对象,以便扩展类中的功能。

我想创建一个“Component”类,并且每个扩展“Component”类的类都有不同的方法,具体取决于组件的需要。我想对扩展超级对象的方法使用术语“describe”。因此,我正在描述该组件。

以下是一个例子:

class Component {
    constructor (args) {
        this.template = args.template;
    }

    getTemplate () {
        return this.template;
    }

    describe () {
    //The magic should happen here
    }
}

类控制器描述符

class Controller {
    constructor () {

    }

    getEvents () {
        return {};
    }
}

扩展Component类。 然后,使用“describe”方法从其他类中注入其他方法。

class example extends Component {
    constructor () {
        super({template: '<div></div>'});
        super.describe({
            Controller
        });

        super.getTemplate();
        super.getEvents();
    }
}

var app = new App({
    example
});

有可能吗?谢谢:))

0 个答案:

没有答案
相关问题