当前位置:网站首页>^28JS是单线程的
^28JS是单线程的
2022-06-09 14:46:00 【sanda_nd】
1、如何证明JS是单线程的?
- setTiimeout()的回调函数是在主线程执行的
- 定时器的回调函数只有在运行栈中的代码全部执行完后,才有可能执行

2、为什么JS要用单线程模式,而不用多线程模式?
- JavaScript的单线程,与它的用途有关
- 作为浏览器的脚本语言,JavaScript的主要用途是与用户互动,以及操作DOM
- 这决定了它只能是单线程,否则会带来很复杂的同步问题
3、代码的分类
初始化代码
回调代码
4、JS引擎执行代码的基本流程
- 先执行初始化代码;包含一些特别的代码 (设置定时器,绑定监听,发送ajax要求,)
- 后面某个时刻才会执行回调代码
边栏推荐
- One month after joining Tencent for outsourcing, I left
- 【论文】Cascade RPN: Delving into high-quality region proposal network with Adaptive Convolution
- 鸿蒙移植i.mx6ull (七) Liteos-a的编译系统
- 百度一程序员被判:不满他人接手项目、彰显自己作用、多次对数据库进行删改,犯破坏计算机信息系统罪
- Using kubekey to build kubernetes/kubesphere environment“
- JS实现JSON数组合并和去重
- Multivariate time series analysis -- causal test
- 【MUI+Flask+MongoDB+HBuilderX】APP开发之答题积分逻辑详解
- tmux(Terminal MultipleXer)命令使用
- I haven't published a thesis for 5 years, and I want to give up my doctoral degree? Ten thousand words self narration of the doctoral director of the University of science and technology of China: he
猜你喜欢

@Enablefeignclients annotation source code analysis

135. 分发糖果

【论文】Cascade R-CNN: Delving into High Quality Object Detection

@EnableFeignClients注解源码解析

Google installs the impression note clipping plug-in

【实战】基于Chromedriver的应用及爬虫相关

860. 柠檬水找零

ECCV 2020 | STAR:基于Transformer的行人轨迹预测模型(二)

How many points can you get if the programmer's college entrance examination paper is exposed?

Error 1062 in database, error reporting
随机推荐
Excel上使用VBA的WebBrowser控件实现单点登录(SSO)
C#/VB.NET 在Word转PDF时生成目录书签
AE脚本-网格参考线黄金分割线生成工具 GuidesUp! 2.2激活版
国货彩妆,败走618
薪酬不变,每周只上四天班,英国试行全球最大规模“四天工作制”
Why do SQL statements use indexes but still slow queries?
Design of cache address mapping and transformation and associated directory table in cache memory
【MUI+Flask+MongoDB+HBuilderX】APP开发之答题积分逻辑详解
【云原生 | Kubernetes篇】深入了解Pod(六)
Leetcode 2001. 可互换矩形的组数(暴力枚举失败了)
C # calculate two time intervals
Critical area, event, mutex, semaphore -- four methods to control multithread synchronization and mutex
China UnionPay (Cloud Computing) fixed-point services: lingqueyun, daocloud, Youyun and Boyun won the bid (Development); Shenzhou information, Tencent cloud and Xinhua three standards (transportation
鸿蒙移植i.mx6ull(十二) 根文件系统
[cloud native | kubernetes] in depth understanding of pod (VI)
GreatSQL如何做中国广受欢迎的开源数据库
v-lazy
鸿蒙移植i.mx6ull(五) 移植概述
金山云 Q1 营收 21.7 亿:其中公有云 13.8 亿、行业云 7.9 亿
[paper] cascade rpn: delving into high quality region proposal network with adaptive revolution