title: Javascript function object with this reference to itself
body: <p>I can't seem to find an example of what I'm trying to achieve, although I'm sure it has been done many times before...</p>
  
  <p>I want to create an object which will have a set of properties and member functions but that I can also call directly. In the same way the jQuery object allows you to call <code>$("selector")</code> or <code>$.method(...)</code></p>
  
  <p>Here's a slimmed down version of what I'm trying to achieve :</p>
  
  <pre><code>var foobar = function(param) {
      return "FOO : " + this.lookup(param);
  }
  
  foobar.vals = {
      1: "one",
      2: "two"
  };
  
  foobar.lookup = function (param) {
      return "BAR : " + this.vals[param];
  }
  
  foobar.lookup("1")
  // returns "BAR : one"
  
  foobar("1")
  // returns error since 'this' points to global scope
  // I'd want it to return "FOO : BAR : one"
  </code></pre>
  
  <p>I've also tried various approaches with function prototype but can't seem to find a method which gives me everything I want...</p>