中調用一個方法,我得到test is not defined
調用stop()方法嘗試將功能
http://jsfiddle.net/n4mKw/1766/
<span id="rotator"></span>
var rotate = {
quoteIndex: -1,
duration: 500,
delay: 3000,
play: true,
quotes: [],
init: function (quotes) {
this.quotes = quotes;
this.showNextQuote();
},
showNextQuote: function() {
this.quoteIndex = (this.quoteIndex + 1) % this.quotes.length;
if (this.play) {
$("#rotator").html(this.quotes[this.quoteIndex])
.fadeIn(this.duration)
.delay(this.delay)
.fadeOut(this.duration, this.showNextQuote.bind(this));
}
},
stop: function() {
this.play = false;
}
};
var test = rotate.init(["example1", "example2", "example3"]);
test.stop();
'rotate.init'不返回任何內容,因此'test'是'undefined' – zerkms