是否可以避免声明全局变量,而是将其分配给匿名函数的结果?
var logged = false;
Ext.each(userRecords, function (userRecord) {
if (userRecord.get('id') == currentuser) {
if (userRecord.get('password') == currentuserpassword) {
logged = true;
}
}
});
例子:
var logged = Ext.each(userRecords, function (userRecord) {
if (userRecord.get('id') == currentuser) {
if (userRecord.get('password') == currentuserpassword) {
return true;
}
}
});