javascript - 为什么 JSLint 比方括号更喜欢点符号?

标签 javascript jquery jslint

我一直在对我的一些代码进行 linting,并收到一些错误提示说最好使用点表示法。我发现我使用的是方括号表示法 ( with clarity from this great post ),但是,我想问一下为什么 Crockford 更喜欢点表示法?我正在从事的项目使用 SBN 是为了它的完整性,我不认为它令人困惑或不可读,但如果有明显的原因需要使用点,我会更正它。

只是想在继续之前完全理解它!

最佳答案

据我对 Crockford 的了解,我认为这归结为一致性和避免使用保留字。在他的site ,他说:

The dot notation can be used when the subscript is a string constant in the form of a legal identifier. Because of an error in the language definition, reserved words cannot be used in the dot notation, but they can be used in the subscript notation.

由于您可以在下标符号中引用保留字,因此可能会造成混淆。基本上,避免使用保留字作为对象成员的名称。点符号强制执行此操作(通过语言——Crockford 称之为错误),因此它被认为是避免使用保留字的更好的编码实践。

同样在同一个网站上,他还表示点符号“更方便一点”。

关于javascript - 为什么 JSLint 比方括号更喜欢点符号?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13271116/

相关文章:

javascript - if 语句内的两个条件 (jQuery)

javascript - 图像隐藏,然后在鼠标移动时再次淡入、淡出和淡入

javascript - 适用于较小屏幕的汉堡菜单,包括 JavaScript/jQuery

javascript - jslint :test for overrideMimeType() property in (new XMLHttpRequest())

javascript - 如何使用 Vue2 一起管理 v-bind 和 v-on?

javascript - 具有 "graphical wrong"空间的数组

javascript - 重新打开 SqueezeBox,不带双动画

javascript - 正则表达式/javascript CamelCase 函数中的连字符

javascript - 新 JSLint : "Unexpected ' .'." explanation

javascript - JSLint : Expected '!!' and instead saw '?'