然而,正如预期的那样,我需要以一系列方式开展这项工作,而不是像现在那样做。
是否有办法在一系列轮 to/回击方法中使用这种说法?
Given something like this:
function f() {
some_async_call({ callback: function(err, results) {...})
}
_(3).times(f);
然后,三个<代码>f 电话将按系列进行,但<代码>sint_async_ calls 电话必定是连续发生的,因为它们是同步的。
如果你要迫使你发出一系列呼吁,那么你就应该利用“yn”呼吁,在系列中发出下一个呼吁:
function f(times, step) {
step = step || 0;
some_async_call({
callback: function(err, results) {
// Do something with `err` and `results`...
if(step < times)
f(times, step + 1);
}
});
}
f(3);
That approach will execute the three some_async_calls
in series but, alas, the initial f(3)
will return immediately. One solution to that problem is, of course, another callback:
function f(from_n, upto, and_finally) {
some_async_call({
callback: function(err, results) {
// Do something with `err` and `results`...
if(from_n < upto)
f(from_n + 1, upto, and_finally);
else
and_finally();
}
});
}
f(0, 3, function() { console.log( all done ) });
<代码>在哪里? : ∗∗∗∗
_.times = function(n, iterator, context) {
for (var i = 0; i < n; i++) iterator.call(context, i);
};
您可以使用250R s async想法,但您必须建立一系列三个功能,但
// Untested off the top of my head code...
function f(callback) {
some_async_call({
callback: function(err, results) {
// Deal with `err` and `results`...
callback();
}
});
}
var three_fs = _(3).range().map(function() { return f });
async.series(three_fs);
但您仍需修改<条码>f条码>,以备有退约功能,如果您总是重打<条码>f条码>。 其后三次:
async.series([f, f, f]);
可能比用<代码>————>积极构建阵列更好。
这里的真正教训是,一旦你履行不尽人意的职能,你就会最终执行你的所有逻辑,作为呼吁退步的退步, all倒一切。
This async library might get you started https://github.com/caolan/async#series
或者,如果你想这样做,想法是在每个功能反馈之后,在源代码。
How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.
I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...
Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...
Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...
I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...
Is it possible for someone to give me a few pointers on how to display a multidimensional array in the form of a bar graph? The array is multidimensional, with three elements in each part - and the ...
Is it possible to reload a form after file-input change? I have a form where the user can chose an image for upload. I also have a php script which displays that image resized. I only wonder if it ...
I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.