Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JavaScript dot notation [duplicate]

The following line is apparently written best in dot notation. I am trying to clean my JavaScript code to make it strict. What does it mean?

if (ie||ns6) {     var tipobj=document.all? document.all["dhtmltooltip"] : document.getElementById? document.getElementById("dhtmltooltip") : ""; } 

I added some context to my line of code, in case this helps? I know nothing about DOM. I am not trying to support Internet Explorer 4, this is not my code and I wouldn't be able to write JavaScript myself. I am only trying to get it compliant and the JSLint tool says about this line:

Problem at line 17 character 43: ['dhtmltooltip'] is better written in dot notation.

like image 715
skarama Avatar asked Jan 04 '10 18:01

skarama


1 Answers

There are two ways to access properties of an object in JavaScript.

Dot notation

foo.bar.baz 

Square bracket notation

foo['bar']['baz'] 

You are using the latter in part of your code.

Douglas Crockford, who wrote JSLint (a tool which gives that error message), is of the opinion that is is better to use dot notation where possible.

like image 196
Quentin Avatar answered Oct 22 '22 10:10

Quentin