【发布时间】:2017-06-23 00:22:50
【问题描述】:
有没有办法为实例的方法声明继承。
//SOME CLASS
class SomeClass{
someMethod{
//SOMETHING HAPPENS
}
}
function myComponent(){
this.subcomponents={
popup:function(){
//SOMETHING HAPPENS
}
}
this.init=()=>{
//NEW INSTANCE OF SUBCOMPONENT POPUP
var popup = new this.subcomponents.popup();
//DESIRED RESULT WOULD BE ABLE TO CALL
popup.someMethod();
}
}
//myComponent inherits someMethod()
myComponent.prototype = new SomeClass();
//IS THERE ANYWAY TO ASSIGN INHERITANCE TO SUBMETHODS OF AN INSTANCE
myComponent.subcomponents.popup.prototype = new SomeClass();
期望的输出是拥有 popup 方法的新实例并继承 SomeClass,这样我就可以调用 popup.someMethod()。
问题:如何分配popup 方法,继承SomeClass 以便调用popup.someMethod()?
【问题讨论】:
标签: javascript object inheritance