subscribe and unsubscribe a function that contains calls to other functions
<p>I have a function that I want to subscribe it to a event queue. When it executes this function I need it to unsubscribe from the queue.</p>

<p><code>functionToExecute</code> is the function I want to execute.</p>

<p><code>onDOMReady</code> subscribes the <code>attachDOMHandler</code> function which in turn executes <code>functionToExecute</code> and unsubscribes itself. I have:</p>

<pre><code>onDOMReady : function(functionToExecute){
        subscribe(this.attachDOMHandler(functionToExecute));
    },
attachDOMHandler : function(functionToExecute) {
        unsubscribe(this.attachDOMHandler(functionToExecute));
        functionToExecute();
    }
</code></pre>

<p>Everything works fine when I have the following:</p>

<pre><code>onDOMReady : function(functionToExecute){
        subscribe(functionToExecute, this, true);
    },
</code></pre>

<p>However I need the function to unsubscribe after it is executed. My plan was to use the <code>attachDOMHandler</code> function which executes the function and has the unsubscribe behaviour.
When I run the former I get a <code>"Uncaught RangeError: Maximum call stack size exceeded"</code> in the Chrome console. It looks like it gets stuck in an infinite loop which makes sense since I keep running <code>attachDOMHandler</code> in the unsubscribe which gets caught in a loop.
I basically need to subscribe a function that I specify by parameter passing. When the function is executed it unsubscribes. 
Hope I have explained this ok.</p>
