53. es5で `extends`を実装する

JavaScript

少し工夫が必要  - 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'

常にもっといい方法を求めよう。