我有这个代码:
if (subject.current == true) {
return;
}
Run Code Online (Sandbox Code Playgroud)
如果subject.current是undefined我想它继续,但现在看来似乎当我检查了真正的失败.我怎样才能做到如果没有定义电流就不会出错?
如果未定义那么它就不是真的.您需要使用或运算符检查两种可能的条件.
if (typeof subject.current === "undefined" || subject.current == true)
Run Code Online (Sandbox Code Playgroud)