引数

2017-10-16 4 views
0

イムトラインこの 'は、この方法:引数

modalshow = new Confirmation(false, this.changea(this), this.changer); 

と確認クラス、このようなものです:

constructor(
    public show: boolean, 
    public actionAccept: Function, 
    public actionReject: Function 
) {} 

しかし、私はエラーを取得しておいてください。

Argument of type 'void' is not assignable to parameter of type 'Function'

だから、私は問題が何であるかを知らないと私は何をすべき行う。

+0

'this.changea(this) 'と' this.changer'の** value **を呼び出して返された** value **を渡しています。彼らは何ですか?ところで、 "void"は[ECMAScript * Type *](http://ecma-international.org/ecma-262/8.0/#sec-ecmascript-language-types)ではありません。 – RobG

答えて

1

あなたが渡す2番目の引数はthis.changea(this)です。この結果、関数changeaの戻り値を渡しています。関数自体は渡していません。

あなたが引数として関数を渡すと、thisの意味を保持したい場合は、あなたが使用することができます。

modalshow = new Confirmation(false,() => this.changea(this), this.changer); 

あなたは今まだ実行されていない機能、でコードをラップしています。

+1

ありがとう、それは完璧に働いた –