这个 if 语句 return empty 在 Bootstrap 模态源代码中做了什么?
What does this if statement return empty do in Bootstrap modal source code?
我正在查看 bootstrap 模态源代码,发现了这样一行。这个 if (!this.isShown || e.isDefaultPrevented()) return
是做什么的?在我看来,无论 if() 中的代码被评估为 false
还是 true
,此代码段中的其余代码仍将被执行。那么设置这样的行并且 return
为空有什么意义呢?
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;
这更像是一条线
if (!this.isShown || e.isDefaultPrevented()){
return;
}
这只是意味着如果模态框已经显示(this.isShown
将为真)或者如果事件的默认操作被阻止,只需从该方法 return without executing any further statements
- 在在这种情况下,这意味着不要隐藏模态。
return
指令立即执行,中断函数的执行。因此,将不会执行任何后续指令。
我正在查看 bootstrap 模态源代码,发现了这样一行。这个 if (!this.isShown || e.isDefaultPrevented()) return
是做什么的?在我看来,无论 if() 中的代码被评估为 false
还是 true
,此代码段中的其余代码仍将被执行。那么设置这样的行并且 return
为空有什么意义呢?
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;
这更像是一条线
if (!this.isShown || e.isDefaultPrevented()){
return;
}
这只是意味着如果模态框已经显示(this.isShown
将为真)或者如果事件的默认操作被阻止,只需从该方法 return without executing any further statements
- 在在这种情况下,这意味着不要隐藏模态。
return
指令立即执行,中断函数的执行。因此,将不会执行任何后续指令。