Skip to content

Instantly share code, notes, and snippets.

@Bambina-zz
Last active August 29, 2015 14:25
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/58983700572ce4b358f9 to your computer and use it in GitHub Desktop.
Save Bambina-zz/58983700572ce4b358f9 to your computer and use it in GitHub Desktop.
js first-class object and first-class function
var x = function(){} //名前のない関数を生成し、変数xに代入している。
var x = new Function("console.log('lalala')") //組み込み関数Functionから、console.logの処理を持つ無名関数を生成し、変数xに代入している。jsの全ての関数は組み込み関数Functionを継承する。
x //=>function anonymous(){console.log('lalala')}を返す。
x() //=>lalala undefined を返す。xに代入された無名関数を実行した。jsの全ての関数はデフォルトで値を返す仕様だが、返り値が定義されていない場合は、undefinedを返す。
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment