queue()
私はここでjqueryについて読んでいました。最初の答えはかなり包括的です:
var theQueue = $({}); // jQuery on an empty object - a perfect queue holder
$.each([1,2,3],function(i, num) {
// lets add some really simple functions to a queue:
theQueue.queue('alerts', function(next) {
// show something, and if they hit "yes", run the next function.
if (confirm('index:'+i+' = '+num+'\nRun the next function?')) {
next();
}
});
});
// create a button to run the queue:
$("<button>", {
text: 'Run Queue',
click: function() {
theQueue.dequeue('alerts');
}
}).appendTo('body');
// create a button to show the length:
$("<button>", {
text: 'Show Length',
click: function() {
alert(theQueue.queue('alerts').length);
}
}).appendTo('body');
しかし、(8行目)がどのように機能しているか理解できませんnext()
。コメントアウトすると、ボタンをもう一度押すまで「次へ」の確認ボックスが表示されないことがわかりますがnext()
、主にDOMをトラバースするために使用されたと思います。ただし、ここでは、関数に再度実行するように指示しているようです。
また、confirm
ボックスのキューイングが関数内にある場合、なぜそれらはすべて、 ?each()
なしで正常にキューイングされるのでしょうか。next()