我在 JS 中创建了这个实用方法:
function IsAuthenticated(userID)
{
var isAuthed = false;
if (userID.length == 0)
return false;
// more logic
if(SomeLogic)
isAuthed = true;
return isAuthed;
}
当我运行这样的东西时,我得到一个对象而不是类型 bool:
if(IsAuthenticated)
//code here
我认为我需要将其转换为 bool 值?
最佳答案
IsAuthenticated
指的是名为“IsAuthenticated”的函数,而不是函数调用。如果您在 IsAuthenticated
上使用 typeof
运算符,您将得到 "function"
:
alert(typeof IsAuthenticated);
所以试试这个:
var userID = /* … */;
if (IsAuthenticated(userID)) {
//code here
}
关于javascript - 检查 bool 正在检查对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3284926/