3

A coworker is running JSLint on our code and fixing the issues that come up. One change he made was to go from this:

document.getElementById(control["value1"]);

to this:

document.getElementById(control.value1);

Is it JSLint's preference to use the dot notation over array brackets? My understanding from here is that the brackets are a bit more flexible, and I wondered what the best practices from the field were.

Kara
  • 6,115
  • 16
  • 50
  • 57
larryq
  • 15,713
  • 38
  • 121
  • 190

1 Answers1

3

Best practice is to use . notation unless you actually need to pass a variable.

This looks more normal, and also allows the JITter to do more intelligent things.

SLaks
  • 868,454
  • 176
  • 1,908
  • 1,964