Hi,

This is a simple question from a beginner in Javascript. I am
wondering if it worth to store result of getElement() in "complex"
object. Does it affect performance dramatically ?

/* In short, do you prefer this : */
{
        frequentlyAccessedNode: null, // remember the frequently accessed
node

        initialize: function () {
                this.frequentlyAccessedNode = MochiKit.DOM.getElement('aNode');
                MochiKit.Signal.connect('anOtherNode', 'onclick', this,
'doSomethingWithTheNode');
        },
        doSomethingWithTheNode: function () {
                var i,
                        MD = MochiKit.DOM;

                for (i = 0; i < 1000; i++) {
                        MD.replaceChildNodes(this.frequentlyAccessedNode, i);
                }
        }
}

/* ... or this ? */
{
        initialize: function () {
                MochiKit.Signal.connect('anOtherNode', 'onclick', this,
'doSomethingWithTheNode');
        },
        doSomethingWithTheNode: function () {
                var i,
                        MD = MochiKit.DOM;

                for (i = 0; i < 1000; i++) {
                        MD.replaceChildNodes('aNode', i);
                }
        }
};

In fact, I did some tests with last firefox and firebug, and I am
impressed to see that there is (almost) no difference in terms of
performance. Can you confirm that ?

Thanks


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"MochiKit" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/mochikit?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to