Created
July 19, 2015 10:43
-
-
Save Bambina-zz/c8948d2032fa2cfef451 to your computer and use it in GitHub Desktop.
js higher-order function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function x(){console.log('lululu')}; //=>undefined | |
function y(func){func();}; //=>undefined | |
y(x); //lululu undefined を返す。関数xを引数として、関数yを呼び出している。 | |
y(function(){console.log('lalala');};) //=>lalala undefinedを返す。無名関数も引数として渡すことができる。 | |
function x(){return function(){ //戻り値に無名関数を返すように定義している。 | |
console.log('lalala'); | |
}; | |
}; | |
var y = x(); //変数yに関数xの実行結果を代入する。実行結果は関数xの戻り値である無名関数である。 | |
y(); //=>lalala undefined を返す。変数yには無名関数が入っており、その無名関数を実行した結果が表示される。 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment