LoginSignup
1
0

More than 3 years have passed since last update.

JavaScriptの関数はオブジェクトに過ぎないのでプロパティを持たせることができる

Posted at

百聞は一見に如かず

function hello() {
  return console.log(`${ hello.message } ${ hello.user }.`)
}
hello.message = 'hello'
hello.user = 'momo'
hello() // -> hello momo.
console.log(hello) // -> { [Function: hello] message: 'hello', user: 'momo' }

面白いですね。
なおhello.nameには関数名(hello)が格納されている。

初めはhello.userではなく、hello.nameで記述したけれど関数名が表示されて、なるほどっと思った。

1
0
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0