Initializing new instances of a class in a loop, how can I persist an assignment to an event handler
        Posted  
        
            by Pydroid
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by Pydroid
        
        
        
        Published on 2010-06-11T07:52:09Z
        Indexed on 
            2010/06/11
            8:02 UTC
        
        
        Read the original article
        Hit count: 272
        
JavaScript
This is a follow on question from http://stackoverflow.com/questions/3020960/why-is-my-prototype-function-not-returning-the-property-of-the-instance
$.getJSON(myjson, function(data) {
        var json = data;
        for (i in json) {
            juuvies[i] = new Juuvy(i,json[i], font, keyfontsize, valfontsize, orbcol, orbkeycol, orbvalcol, paper);
            juuvies[i].juuv_it();
            var mykey = juuvies[i].init_nodes();
                            juuvies[i].orb.node.onmouseover = function() { console.log(mykey);};
        }
    });
And my init_nodes function,
Juuvy.prototype.init_nodes = function() { return this.key; }
At this point of time, I get only the last key in the loop, instead of a unique pass each time. Is there a way I can persist the assignment for the event handler?
© Stack Overflow or respective owner