2021年9月15日
摘要: 题目:写出下面代码输出的结果,并做解释 // counter.js let counter = 10; let add = () => { console.log(counter); } export { counter, add }; // index.js add(); import { cou 阅读全文
posted @ 2021-09-15 15:06 pleaseAnswer 阅读(96) 评论(0) 推荐(0) 编辑
摘要: 如何实现异步io? 1.回调函数callback 优点:解决了同步的问题(只要有一个任务耗时很长,后面的任务都必须排队等待,会拖延整个程序的执行) 缺点:回调地狱,不能用 try catch 捕获错误,不能 return 2.Promise 优点:解决了回调地狱的问题 缺点:无法取消 Promise 阅读全文
posted @ 2021-09-15 10:26 pleaseAnswer 阅读(77) 评论(0) 推荐(0) 编辑
摘要: js是一门 单线程 语言,一切js的多线程都是用单线程模拟出来的 1. 单线程任务 同步任务、异步任务 同步任务进入主线程,异步任务进入Event Table并注册函数 当指定事件完成时,Event Table会将这个函数移入Event Queue 主线程内的任务执行完毕为空,会去Event Que 阅读全文
posted @ 2021-09-15 09:26 pleaseAnswer 阅读(60) 评论(0) 推荐(0) 编辑