【发布时间】:2013-09-02 06:22:03
【问题描述】:
我有以下似乎正确的代码片段,但 jslint 不喜欢它。
var VALID_TYPE = {
"stringType" : "string",
"arrayType" : "array",
"objectType" : "object"
},
DEFAULT_FIRST = 1, DEFAULT_LAST = 1, PRIMITIVE_TYPE = {
"stringType" : "string",
"arrayType" : "array",
"objectType" : "object",
"undefinedType" : "undefined",
"booleanType" : "boolean",
"numberType" : "number"
};
VALID_TYPE.toString = function () {
var types = [], currentType;
for (currentType in this) {
if (typeof this[currentType] === PRIMITIVE_TYPE.stringType) {
types.push(this[currentType]);
}
}
var outputString = types.join(', ');
return outputString;
};
错误的行是这样的,在“.”处: if (typeof this[currentType] === PRIMITIVE_TYPE.stringType) {
错误的确切文本是: 需要一个字符串,但看到的是 '.'。
toString() 按预期执行。除了将表达式的右侧放入另一个变量之外,我看不到应该更改什么以避免错误。 jslinterrors.com 上尚未描述该错误。
【问题讨论】:
-
当您将
typeof与非常数进行比较时,JSLint 似乎不喜欢它。不知道为什么...
标签: javascript jslint