53. es5で `extends`を実装する
シェアしよう
少し工夫が必要 - accepted / - tried
extends を使ったことは絶対あでしょう。
extends
と(ほぼ)同様に動くES5のmyExtends()
を作ってください!
myExtends()
はSubType とSuperTypeを受け、新しいタイプを返す。
const InheritedSubType = myExtends(SuperType, SubType)
const instance = new InheritedSubType()
// 上記のコードは下のコードと(ほぼ)同じ動くに
class SubType extends SuperType {}
const instance = new SubType()
この問題を完成するには、JavaScriptでの継承を完全に理解した方がいい
補足
BFE.devでは以下のSuperTypeと SubTypeでジャッジします。
function SuperType(name) {
this.name = name
this.forSuper = [1, 2]
this.from = 'super'
}
SuperType.prototype.superMethod = function() {}
SuperType.prototype.method = function() {}
SuperType.staticSuper = 'staticSuper'
function SubType(name) {
this.name = name
this.forSub = [3, 4]
this.from = 'sub'
}
SubType.prototype.subMethod = function() {}
SubType.prototype.method = function() {}
SubType.staticSub = 'staticSub'