title: How to convert an "object" into a function in JavaScript?
body: <p>JavaScript allows functions to be treated as objects--if you first define a variable as a function, you can subsequently add properties to that function.  How do you do the reverse, and add a function to an "object"?</p>
  
  <p>This works:</p>
  
  <pre><code>var foo = function() { return 1; };
  foo.baz = "qqqq";
  </code></pre>
  
  <p>At this point, <code>foo()</code> calls the function, and <code>foo.baz</code> has the value "qqqq".</p>
  
  <p>However, if you do the property assignment part first, how do you subsequently assign a function to the variable?</p>
  
  <pre><code>var bar = { baz: "qqqq" };
  </code></pre>
  
  <p>What can I do now to arrange for <code>bar.baz</code> to have the value "qqqq" <em>and</em> <code>bar()</code> to call the function?</p>