title: Pattern needed: create new object that returns an executeable function and inherits from a prototype
body: <p>Scenario 1 - everything works:</p>
  
  <pre><code>var AwesomeObject = function()
  {
     var self = this;
     self.whatstuff = 'really awesome';
  }
  
  AwesomeObject.prototype.doStuff = function()
  {
     var self = this;
     console.log('i did '+self.whatstuff+' stuff');
     return self;
  }
  
  var awesome = new AwesomeObject(); //returns a new AwesomeObject
  awesome.doStuff(); // prints 'i did really awesome stuff' on the console
  </code></pre>
  
  <p>Now i want it even awesomer:</p>
  
  <pre><code>var AwesomeObject = function()
  {  
     var f = function() { console.log('i am awesome'); }
     var self = f;
     self.whatstuff = 'really awesome';
     return self;
  }
  
  AwesomeObject.prototype.doStuff = function()
  {
     var self = this;
     console.log('i did '+self.whatstuff+' stuff');
     return self;
  }
  
  var awesome = new AwesomeObject(); //returns the interal f object
  awesome(); // prints 'i am awesome'
  awesome.doStuff(); // throws an error
  </code></pre>
  
  <p>new AwesomeObject should return an executable function itself, so that i can say 'awesome();'</p>
  
  <p>but i want it to inherit the <code>AwesomeObject.prototype</code>, too.</p>
  
  <p>adding <code>self.prototype =  AwesomeObject.prototype;</code> does not help.</p>
  
  <pre><code>var AwesomeObject = function()
  {  
     var f = function() { console.log('i am awesome'); }
     var self = f;
     self.whatstuff = 'really awesome';
     self.prototype =  AwesomeObject.prototype;
     return self;
  }
  </code></pre>
  
  <p>ok i can copy the <code>AwesomeObject.prototype</code> functions - one after the other - into the scope of <code>f</code> </p>
  
  <pre><code>var AwesomeObject = function()
  {  
     var f = function() { console.log('i am awesome'); }
     var self = f;
     self.whatstuff = 'really awesome';
     self.doStuff =  function() { AwesomeObject.prototype.doStuff.apply(self,arguments); }
     return self;
  }
  </code></pre>
  
  <p>but i think there must be a better way, a better pattern, what is it?</p>
  
  <p>this issue drives me crazy, help would be really appreciated. </p>
  
  <p>in general: how to create a function object that </p>
  
  <ul>
  <li>can be created with new</li>
  <li>returns a function object that can be executed</li>
  <li>inherits all properties and methods of a given prototype </li>
  </ul>
  
  <p>?</p>
  
  <p>is there a way?</p>
  
  <p>thx
  Franz</p>