返回列表 發帖

js 語法中的"~"符號

本帖最後由 pix756 於 2019-7-18 13:47 編輯

最近在開發網站,有使用到一個jQuery 的 autoComplete套件,
其中的語法有個符號 "~"代表什麼意思?
請各位先進解惑了,謝謝~
語法如下:
$("input[name='demo']").autoComplete({
        minChars: 1,
        source: function(term, suggest){
                term = term.toLowerCase();
                var choices = [book, phone, table];
                var matches = [];
                for (i=0; i<choices.length; i++)
                        if (~choices[i].toLowerCase().indexOf(term)) matches.push(choices[i]);
                suggest(matches);
        }
});

~ 是位元操作運算符,做 NOT 運算的,會讓位元中的 0 變成 1,而 1 則是變成 0
To infinity and beyond!

TOP

返回列表 回復 發帖