JavaScript点表示法 [英] JavaScript dot notation
问题描述
以下一行显然是用点表示法编写的。我正在尝试清理我的JavaScript代码以使其严格。这是什么意思?
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") : "";
}
我在代码行中添加了一些上下文,如果有帮助的话?
我对 DOM 一无所知。我不是要支持Internet Explorer 4,这不是我的代码,我自己也无法编写JavaScript。我只是试图让它符合要求并且 JSLint 工具说明了这一行:
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:
17行字符43的问题:['dhtmltooltip']最好用点表示法编写。
Problem at line 17 character 43: ['dhtmltooltip'] is better written in dot notation.
推荐答案
点符号
foo.bar.baz
Square括号表示法
foo['bar']['baz']
您在部分代码中使用后者。
You are using the latter in part of your code.
Douglas Crockford,谁编写了JSLint(一个提供该错误消息的工具),认为在可能的情况下最好使用点符号。
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.
这篇关于JavaScript点表示法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!