2016-04-26 20 views
-1

JavaScriptでは、関数は「ファーストクラスの市民」です。しかし、私は、関数に引数として渡されたときにそれらがどのように評価されるかについて少し混乱しています。引数が渡されたときに関数が評価される方法

const childFunction =() => (
... 
); 

const parentFunction = (childFunction) =>(
... 
); 

私はコードの流れのシーケンスが何であるか疑問に思っています。それでこのようなものになるでしょう:

'parentFunction'が実行されます。引数 'childFunction'は引数として識別され、 'childFunction'が実行されます。 'childFunction'から結果を受け取ると、 'parentFunction'の本体が実行されますか?

おかげで、

+1

を使用して、それを呼び出すために 'childFunction'は場合にのみ実行されたと' parentFunction'はそれを実行したとき。暗黙のうちに実行されることはありません。 –

+1

@squintありがとう、それは完璧な意味があります。 – Kayote

答えて

2

childFunctionはちょうど引数として渡されることによって実行されていません。 childFunctionを取る関数はchildFunction()または​​

const childFunction =() => (
... 
); 

const parentFunction = (childFunction) =>(
    // childFunction doesn't get called/executed until this line is reached 
    childFunction(); 
    // Or something like 
    childFunction.call(this, 1,2,3); 
... 
); 
関連する問題