["display"] is better written in dot notation
103 else if (elem.currentStyle)
104 {
105 // For MSIE, naturally
106 var disp = elem.currentStyle['display'];107 }
108 else if (window.getComputedStyle)
109 {
["display"] is better written in dot notation
98 if (elem.style && elem.style['display'])
99 {
100 // Only works with the "style" attr
101 var disp = elem.style['display'];102 }
103 else if (elem.currentStyle)
104 {
["display"] is better written in dot notation
95{
96 elem = document.getElementById(elem);
97
98 if (elem.style && elem.style['display']) 99 {
100 // Only works with the "style" attr
101 var disp = elem.style['display'];
Description
In JavaScript, there are two ways to access the properties of an object:
- dot-notation
(object.property)
( Recommended ) - square-bracket notation
(object["property"])
( Bad Practice )
The dot notation is preferred because it is easier to read, less verbose, and works better with aggressive JavaScript minimizers.
Bad Practice
const x = object["property"];
Recommended
const x = object.property;
x = object[y];