今天看到大佬重構我的囉嗦代碼時
用到了
xxx & xxx
xxx |= xxx
let errorMsg = "";
if (this.flag & TipType.InputNull)
errorMsg += "文件名不能爲空! "
if (this.flag & TipType.StrIllegal)
errorMsg += `文件名不能包含下列字符:\ / : * ? " < > | `;
if (this.flag & TipType.isExist)
errorMsg += "已存在同名文件,仍然使用該命名嗎?";
以及
if (this.regex.test(inputValue))
this.flag |= TipType.StrIllegal;
else if (inputValue === "")
this.flag |= TipType.InputNull;
問後得知是按位運算
爲什麼要把原來的絕對比較 ===
、 !==
更換爲按位運算呢
我還沒想通。。。。
雖然被說了一頓基礎知識薄弱 但是學到了不虧
真想知道該從哪裏學習到這些東西