Rule Definition
Every time the interpreter encounters a dot character, it will look up the child variable against the parent. For example, var hourHand=myGrandFather.clock.hands.hour make three lookup. When used too much in a loop, dot notation can affect performance of a javascript function. Reducing the dotation usage can win 50% of the time consumed by this function.
Remediation
Use intermediate variable to minimize the number of dot within the loop.
Violation Code Sample
for (var i=0;i<data;i+=1){
var hourHand=myGrandFather.clock.hands.hour;
var minuteHand=myGrandFather.clock.hands.minute;
var secondHand=myGrandFather.clock.hands.second;
...
} // VIOLATION "myGrandFather.clock.hands" has been referenced more than 2 times
Fixed Code Sample
for (var i=0;i<data;i+=1){
var hands = myGrandFather.clock.hands;
var hourHand=hands.hour;
var minuteHand=hands.minute;
var secondHand=hands.second;
...
}
Reference
AJAX in Action - Manning - ISBN 1-932394-61-3 page 296
Related Technologies
HTML5
Technical Criterion
CWE-1050 - Excessive Platform Resource Consumption within a Loop
About CAST Appmarq
CAST Appmarq is by far the biggest repository of data about real IT systems. It's built on thousands of analyzed applications, made of 35 different technologies, by over 300 business organizations across major verticals. It provides IT Leaders with factual key analytics to let them know if their applications are on track.