Jak*_*her 1 javascript deferred async-await d3.js
为什么在这个很小的示例中未调用.await函数?
的HTML
<h1>test</h1>
<div id="a"></div>
<div id="b"></div>
Run Code Online (Sandbox Code Playgroud)
JS
d3.queue()
.defer(a,1)
.await(b,2);
function a(x){
d3.select('#a').text("a is executing with x="+x);
}
function b(err,x){
d3.select('#b').text("b is executing with x="+x);
}
Run Code Online (Sandbox Code Playgroud)
输出量
test
a is executing with x=1
Run Code Online (Sandbox Code Playgroud)
@altocumulus用他的有见地的评论击败了我,但是由于一个例子讲了千字:
<!DOCTYPE html>
<html>
<head>
<script src="https://d3js.org/d3.v4.min.js"></script>
</head>
<body>
<h1>test</h1>
<div id="a"></div>
<div id="b"></div>
<script>
var q = d3.queue()
.defer(a, 1, 2)
.await(b);
function a(x, y, callback) {
d3.select('#a').text("a is executing with x=" + x);
callback(null, y);
}
function b(err, x) {
d3.select('#b').text("b is executing with x=" + x);
}
</script>
</body>
</html>Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
867 次 |
| 最近记录: |