嘿,大家好,我对 JS 和 jQuery 不太熟悉,我刚刚浏览了 carousel.js 的源代码,发现了以下代码行:
this.cycle(true)
现在循环函数看起来像这样:
Carousel.prototype.cycle = function (e) {
// console.log('inside cycle');
e || (this.paused = false)
this.interval && clearInterval(this.interval)
this.options.interval
&& !this.paused
&& (this.interval = setInterval($.proxy(this.next, this), this.options.interval))
return this
}
如果我console.log(e)
,我永远不会得到“true”为什么?
我所指的行可以找到 here 。
有人可以向我解释为什么 this.cycle()
会在该行传递值 true
吗?
谢谢。
最佳答案
循环函数内的console.log(e)应返回true。但更容易理解的代码分割是这样的:
Carousel.prototype.cycle = function (e) {
// console.log('inside cycle');
//e || (this.paused = false)
if(!e){
this.paused=false;
}
//this.interval && clearInterval(this.interval)
if(this.interval){
clearInterval(this.interval);
}
/*
this.options.interval
&& !this.paused
&& (this.interval = setInterval($.proxy(this.next, this), this.options.interval))
*/
if(this.options.interval && !this.paused){
this.interval = setInterval($.proxy(this.next, this), this.options.interval)
}
return this
}
关于javascript - 了解 Bootstrap 轮播代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29859709/