How to print all functions of JavaScript non-objects?
<p>If I have <code>var foo = 'bar';</code>, how do I get all the functions callable on <code>foo</code>, such as <code>toUpperCase</code>? It's not an object, so <a href="http://stackoverflow.com/a/2258232/96588">Object.getOwnPropertyNames(foo)</a> doesn't work:</p>

<pre><code>$ node
&gt; var foo = 'bar';
undefined
&gt; 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.&lt;anonymous&gt; (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)
</code></pre>

<p><a href="http://stackoverflow.com/a/10312446/96588">katspaugh's simple, elegant solution</a>:</p>

<pre><code>&gt; console.log(Object.getOwnPropertyNames(foo.constructor.prototype));
[ 'constructor',
  'length',
  'toLowerCase',
  ... ]
undefined
</code></pre>
