Skip to content

Instantly share code, notes, and snippets.

@Bambina-zz
Created July 19, 2015 10:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Bambina-zz/c8948d2032fa2cfef451 to your computer and use it in GitHub Desktop.
Save Bambina-zz/c8948d2032fa2cfef451 to your computer and use it in GitHub Desktop.
js higher-order function
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