|
|
Deep Nesting of Objects - Javascript
|
Views : 239
|
|
Tagged in : Javascript
|
|
|
Report This Scrap as Inappropriate We request you to choose the appropriate categroy and subcategory that suits your
objectionable concern about the scrap, So that our team can review and find out whether it violates our Guidelines or the
scrap is not suitable for all viewers.
|
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. |
|
By Geethalakshmi, On - 2010-09-16 |
|
|
|