2 Replies Latest reply on Jul 13, 2007 1:48 PM by cayennecode

    assigning props/functions with for loop vs directly

    cayennecode Level 1
      Say you have X number of objects, and you want to assign a value to their properties, or add an EventListener.

      You could list all X number of objects, and set their property values as such ( objectX.property = value )

      Of course that'd be silly if X number of objects was 100, or even 10...I'm lazy.

      So instead you put X number of objects into an array, and loop through that array adding values to their properties.

      I'm simply curious as to what runtime performance difference there would be. Anyone tried anything like this, or care to speculate in theory?
        • 1. Re: assigning props/functions with for loop vs directly
          Level 7
          cayennecode,

          > Of course that'd be silly if X number of objects was 100, or
          > even 10...I'm lazy.

          Heh, I've been known to loop for only three objects. It depends on how
          much is going on with the various assignments. If they're long/complex
          enough, a loop saves typing.

          > I'm simply curious as to what runtime performance difference
          > there would be. Anyone tried anything like this, or care to
          > speculate in theory?

          In my experience, runtime performance isn't affected (or if it is, it's
          affected a negligible amount). Dynamic assignment is an
          author-time/programmer's convenience, and also comes in handy when the
          number of objects to be assigned is unknown. Those are the primary benefits
          I see.


          David Stiller
          Adobe Community Expert
          Dev blog, http://www.quip.net/blog/
          "Luck is the residue of good design."


          • 2. Re: assigning props/functions with for loop vs directly
            cayennecode Level 1
            >Heh, I've been known to loop for only three objects. It depends on how
            >much is going on with the various assignments. If they're long/complex
            >enough, a loop saves typing.

            HAH! I hear that!