がある場合、 などでvar foo = 'bar';
呼び出し可能なすべての関数を取得するにはどうすればよいですか? これはオブジェクトではないため、Object.getOwnPropertyNames(foo)は機能しません:foo
toUpperCase
$ node
> var foo = 'bar';
undefined
> console.log(Object.getOwnPropertyNames(foo));
TypeError: Object.getOwnPropertyNames called on non-object
at Function.getOwnPropertyNames (native)
at repl:1:20
at REPLServer.eval (repl.js:80:21)
at repl.js:190:20
at REPLServer.eval (repl.js:87:5)
at Interface.<anonymous> (repl.js:182:12)
at Interface.emit (events.js:67:17)
at Interface._onLine (readline.js:162:10)
at Interface._line (readline.js:426:8)
at Interface._ttyWrite (readline.js:603:14)
katspaugh のシンプルでエレガントなソリューション:
> console.log(Object.getOwnPropertyNames(foo.constructor.prototype));
[ 'constructor',
'length',
'toLowerCase',
... ]
undefined