- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" " http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
- <html>
- <head>
- <title> New Document </title>
- <script>
- var queue = function(funcs, scope) {
- (function next() {
- if(funcs.length > 0) {
- funcs.shift().apply(scope || {}, [next].concat(Array.prototype.slice.call(arguments, 0)));
- }
- })();
- };
- var obj = {
- value: null
- };
- queue([
- function(callback) {
- this.value = 10;
- alert("A"+this.value);
- setTimeout(function() {
- callback(20);
- }, 2000);
- },
- function(callback, add) {
- alert("B"+(this.value + add));
- callback();
- },
- function() {
- alert("C"+obj.value);
- }
- ], obj);
- </script>
- </head>
- <body>
- </body>
- </html>
- //该片段来自于http://www.codesnippet.cn/detail/1808201410201.html
来源: http://www.codesnippet.cn/detail/1808201410201.html