我有以下代码片段似乎是正确的,但jslint不喜欢它。jslint给予预期的字符串,而不是看到{a}
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;
};
错误路线是这样的,在所述 “”: 如果(typeof运算此[currentType] === PRIMITIVE_TYPE.stringType){
错误的确切文本是: 预期一字符串,而是看到'。'。
toString()按预期执行。除了将表达式的右侧放入另一个变量之外,我无法看到应该更改以避免错误。该错误尚未在jslinterrors.com上描述。
它看起来像JSLint不喜欢它,当你比较'typeof'到一个非常量。不知道为什么... – SLaks