Deep Nesting of Objects

by Geethalakshmi 2010-09-16 21:26:09

Deep Nesting of Objects


If you need to do multiple operations on a deeply nested object, it's better to store a reference to it in a temporary variable instead of dereferencing it each time. For example, suppose that you want to do a series of operations on a textfield accessible by the following construct:

document.forms[0].elements[0]


It's recommended that you store a reference to the textfield in a variable, and use this variable instead of the above construct:

var field = document.forms[0].elements[0];
// Use field in loop


Each dot results in an operation to retrieve a property, in a loop, these operations do add up, so it's better to do it once, store the object in a variable, and re-use it.

Tagged in:

928
like
0
dislike
0
mail
flag

You must LOGIN to add comments