如果我有var foo = 'bar';
,我如何获得所有可调用的函数foo
,例如toUpperCase
?它不是一个对象,所以Object.getOwnPropertyNames(foo)不起作用:
$ 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)
> console.log(Object.getOwnPropertyNames(foo.constructor.prototype));
[ 'constructor',
'length',
'toLowerCase',
... ]
undefined