1
我繼承了一個JavaScript代碼庫,我是JavaScript新手。所以我使用JSHint來避免常見錯誤,誤用。如何避免這種邪惡eval的情況?
JSHint發現這段代碼,但我不知道如何避免邪惡的eval:
function GetProperties(object) {
var result, property, t;
result = '';
for (property in object) {
if (property.indexOf('Get', 0) === 0) {
t = object[property] + "...";
eval("if (GetNumOfParameter(t) == 0) var m = object." + property + "(); else var m = -100;");
if (window.m != -100) {
result += property + ': ' + window.m + '\r\n';
}
}
}
return result;
}
'var m = object [property]()'也許? – 2012-04-19 14:28:41