1 Star 0 Fork 0

Eugene/js-event-loop

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
test.html 1.87 KB
一键复制 编辑 原始数据 按行查看 历史
egu0 提交于 2024-04-23 22:54 . submit
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<div id="app">
{{ message }}
</div>
</body>
<script>
for (let i = 0; i < 5; i++) {
setTimeout(function () {
console.log('异步任务', i);
}, 200);
}
console.log('同步任务', i);//Uncaught ReferenceError: i is not defined
</script>
<!-- <script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
<script>
var app = new Vue({
el: '#app',
data: {
message: 'Hello Vue!'
}
})
setTimeout(function () {
console.log('定时器setTimeout')//5
}, 0);
new Promise(function (resolve) {
console.log('同步任务1');//1
for (var i = 0; i < 10000; i++) {
i == 99 && resolve();
}
}).then(function () {
console.log('Promise.then')//3
});
app.$nextTick(() => {
console.log('nextTick')//4
})
console.log('同步任务2');//2
</script> -->
<!-- <script>
setTimeout(() => {
console.log('1')
Promise.resolve().then(() => {
console.log('2')
})
}, 0)
new Promise((resolve, reject) => {
console.log('3')
resolve()
})
.then(res => {
console.log('4');
})
console.log('5')
</script> -->
<!--
<script>
console.log('1')
setTimeout(function callback() {
console.log('2')
}, 1000)
new Promise((resolve, reject) => {
console.log('3')
resolve()
})
.then(res => {
console.log('4');
})
console.log('5')
</script> -->
<!-- <script>
console.log('1')
setTimeout(function () {
console.log('2')
}, 1000)
console.log('3')
</script> -->
</html>
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/egu0/js-event-loop.git
[email protected]:egu0/js-event-loop.git
egu0
js-event-loop
js-event-loop
master

搜索帮助