Javascript 这个if语句返回empty在引导模式源代码中做什么?
我正在检查引导模式的源代码,发现了这样一行代码。如果(!this.isShown | | e.isDefaultPrevented())返回该怎么办?在我看来,无论if()中的代码的计算结果是Javascript 这个if语句返回empty在引导模式源代码中做什么?,javascript,twitter-bootstrap,bootstrap-modal,Javascript,Twitter Bootstrap,Bootstrap Modal,我正在检查引导模式的源代码,发现了这样一行代码。如果(!this.isShown | | e.isDefaultPrevented())返回该怎么办?在我看来,无论if()中的代码的计算结果是false还是true,此代码段中的其余代码仍将被执行。那么,将这样的行设置为并返回空有什么意义呢 Modal.prototype.hide = function (e) { if (e) e.preventDefault() e = $.Event('hide.bs.modal')
false
还是true
,此代码段中的其余代码仍将被执行。那么,将这样的行设置为并返回空有什么意义呢
Modal.prototype.hide = function (e) {
if (e) e.preventDefault()
e = $.Event('hide.bs.modal')
this.$element.trigger(e)
if (!this.isShown || e.isDefaultPrevented()) return
this.isShown = false
this.escape()
this.resize()
$(document).off('focusin.bs.modal')
this.$element
.removeClass('in')
.attr('aria-hidden', true)
.off('click.dismiss.bs.modal')
.off('mouseup.dismiss.bs.modal')
this.$dialog.off('mousedown.dismiss.bs.modal')
$.support.transition && this.$element.hasClass('fade') ?
this.$element
.one('bsTransitionEnd', $.proxy(this.hideModal, this))
.emulateTransitionEnd(Modal.TRANSITION_DURATION) :
this.hideModal()
}
这是更多的一个班轮为这个
if (!this.isShown || e.isDefaultPrevented()){
return;
}
这仅仅意味着如果模式已经显示(This.isShown
将为true)或者如果事件的默认操作被阻止,只需从该方法返回,而不执行任何进一步的语句
——在这种情况下,这意味着不要隐藏模式。返回指令是立即的,会中断函数的执行。因此,以下任何指令都不会执行。If
语句中的If代码将被计算为true
,return
将阻止其余代码执行“在我看来,无论If()中的代码是什么,此代码段中的其余代码仍将被执行”-为什么?
if (!this.isShown || e.isDefaultPrevented()){
return;
}