1

を拡張するクラスを作成しようとしていますFunction

var MyClass = class MyClass extends Function {
  constructor(func, /*some other things*/) {
    //this is not defined in extended classes for some reason
    var newThis = func;
    //assign other stuff to newThis
    return newThis;
  }

  //methods

}

最初はこれでうまくいくと思っていましたが、instanceofチェックの結果、作成されたオブジェクトはメソッドやプロパティを一切持たない通常の関数であることがわかりました。それで、superキーワードをconstructaに使用する必要があることに気付きましたFunction

var newThis = super(func.toString().split('(')[1].split(')')[0].split(','),
                    func.toString().split('{')[1].split('}')[0])

これは機能しますが、コンテンツ セキュリティ ポリシー (そのようなもの) に準拠していないため、Chrome アプリでは機能しません。

4

1 に答える 1