jQuery-style function that can be accessed like an object
<p>I am creating an AJAX API for a web service and I want to be able to call jQuery-like accessors. 
jQuery seems to be able to execute 'jQuery' as a function, but also use it to directly access the object that is the result of the function EG:</p>

<pre><code>jQuery();
jQuery.each({});
</code></pre>

<p>This is the trick that I can't seem to pull off:</p>

<pre><code>myAPI('foo'); //output: 'foo'
myAPI('foo').changeBar(); //output: 'foo' 1
myAPI.changeBar(); //Error: not a function
</code></pre>

<p>I have seen the answers to similar questions, which are helpful, but don't really answer my question.</p>

<p><a href="http://stackoverflow.com/questions/8734115/how-can-jquery-behave-like-an-object-and-a-function">#8734115</a> - Really interesting, but you can't access the methods that were set by f.prototype.</p>

<p><a href="http://stackoverflow.com/questions/2953314/javascript-function-like-objects-i-e-can-be-used-as-a-function-e-g-as">#2953314</a> - Uses Multiple operations to create object instead of a single function.</p>

<p>here is my code:</p>

<pre><code>(function(window) {

        var h = function(foo) {
                // The h object is actually just the init constructor 'enhanced'
                return new h.fn.init(foo);
        };
        /**
         * Methods defined at protoype.
         */
        h.fn = h.prototype = {
            constructor: h,
            init: function(foo) {
                console.log(foo);
                return this;
            },
            splice : function () {},
            length : 0,
            bar : 0,
            changeBar : function() {
                this.bar++;
                return this.bar;
            }
        };
        h.fn.init.prototype = h.fn;

    //Publish 
    window.myAPI =h;

}( window));
</code></pre>

<p>I'm sure I'm missing something simple :(</p>
