var o={flag:true}; var test=!!o.flag;//等效于var test=o.flag||false; alert(test);
由于对null与undefined用!操作符时都会产生true的结果,
所以用两个感叹号的作用就在于,
如果明确设置了o中flag的值(非 null/undefined/0""/等值),自然test就会取跟o.flag一样的值;
如果没有设置,test就会默认为false,而不是 null或undefined。
IccHelper.addEventListener('iccinfochange', function () { var keyCbmi = 'ril.icc.cbmi.CbChannels'; var keyCbmir = 'ril.icc.cbmir.CbChannels'; self._iccCbmChannelList = []; if (IccHelper.cardState == 'ready') { var reqcblCbmi = navigator.mozSettings.createLock().get(keyCbmi); reqcblCbmi.onsuccess = function () { dump('tcl_cbm>>ril.icc.cbmi.CbChannels:' + reqcblCbmi.result[keyCbmi]); var vendorCbmiList = reqcblCbmi.result[keyCbmi]; if (!!vendorCbmiList) { for (var i = 0; i < vendorCbmiList.length; i++) { if (checkCbcValid(self._iccCbmChannelList ,String(vendorCbmiList[i]))) { self._iccCbmChannelList.push(String(vendorCbmiList[i])); } } } dump('tcl_cbm>>ril.icc.cbmi.CbChannels>>this._iccCbmChannelList=' + JSON.stringify(self._iccCbmChannelList)); };