jQuery Delegate callback
<p>I'm having some problems with the handler callback using <code>.delegate()</code> in jQuery.  This setup uses 2 files- on where $B is created, and the other a simple $(doc).ready file. </p>

<p>I have an SVG file with a bunch (50+) of <code>&lt;g&gt;</code> tags I need to track when I click, rollover, rollout, etc. Instead of attaching the functions to the <code>&lt;g&gt;</code> nodes, delegate looked like a cleaner option.  </p>

<p>However, I'm running into an issue which I think is my relative lack of knowledge on JavaScript.</p>

<p>Here's the setup for my main ready() file:</p>

<pre><code>$C.Events.onStation({
    click : function(e){
        console.log(e)
            return false;
    },
    mouseenter : function(e){
        return false;
    },
    mouseleave : function(e){
        return false;
    }
})
</code></pre>

<p>That works fine.  Everything's passed through, etc. Inside my $B.Events Object:</p>

<pre><code>Events : new function(){
    var _station = function(obj){
        // delegate the events to the primary SVG node
        for(var type in obj){
            $(City.Map.node).delegate('g', type, function(){
            obj[type]()
        })
    }
    return {
        onStation : _station
    }
    // others taken out for relevance
}()
</code></pre>

<p>Now, with this, if I just pass in <code>obj[type]</code> instead of wrapping it in another function, it works fine.  Only problem with that is I need to do some pre-work with the function being passed in (i.e. messing with the event data object) as well as moving all the <code>return false</code>'s into the delegation code and not muck up my other file.</p>

<p>So how can I get the functions from the first code block executed within the callback handler function in jQuery's <code>.delegate()</code> function?</p>

<p><strong>Edit in Response</strong></p>

<p>I think it's a step in the right direction.  I had a feeling it had something to due with the nature of JS and not necessarily the logic.  It's why I hate Javascript sometimes.</p>

<p>The problem with this solution is it's passing a primitive to a generic builder function.  I need to store and return an executable function.  The few things I've tried have been unsuccessful.  Here's an example of the many things I tried:</p>

<pre><code>var _station = function(events){
    var _funcs = {}
    var _selection = null;

    var create = function(f){
        return function(){ return f() }
    }
    for(var t in events){
        _funcs[t] = create(t, events[t])
    }
    console.log(_funcs)

    // delegate the events to the primary SVG node
    for(var type in events){
        $('#stations', Bart.Map.node).delegate('g', type, function(e){                
            _funcs[type](e)
            e.stopPropagation()
        })
    }
}
</code></pre>

<p>When I <code>log(_funcs[type])</code> it comes back as a function, but I can't execute it for the life of me.  </p>

<p>This closure stuff kills me.  </p>
