我正在使用JSLint来提取以下代码:
'use strict';
var mathService = {
add: add,
subtract: subtract,
multiply: multiply,
divide: divide,
power: power,
squareRoot: squareRoot
};
function add(first, second) {
return first + second;
}
function subtract(first, second) {
return first - second;
}
function multiply(first, second) {
return first * second;
}
function divide(first, second) {
return first / second;
}
function power(first, second) {
return Math.pow(first, second);
}
function squareRoot(first) {
return Math.sqrt(first);
}
当我尝试lint此代码时,我收到对象中每个属性的错误消息,指出它未定义。但是,我不认为必须定义对象属性?在此先感谢您的帮助!
答案 0 :(得分:2)
在函数之后移动对象,如
"use strict";
function add(first, second) {
return first + second;
}
function subtract(first, second) {
return first - second;
}
function multiply(first, second) {
return first * second;
}
function divide(first, second) {
return first / second;
}
function power(first, second) {
return Math.pow(first, second);
}
function squareRoot(first) {
return Math.sqrt(first);
}
var mathService = {
add: add,
subtract: subtract,
multiply: multiply,
divide: divide,
power: power,
squareRoot: squareRoot
};
你会得到一些警告,但没有错误。