what's the print number means after called the setTimeout function in Chrome console?
what's the print number means after called the setTimeout function in Chrome console?
javascript function return value / js 函数返回值

timeoutID
const log = console.log;
// undefined
setTimeout(() => log(`zero`), 0);
// 3194
// zero
setTimeout(() => log(`zero`), 1000);
// 3202
// zero
setTimeout(`;`);
// 3212
setTimeout(`;`);
// 3215
setTimeout
timeoutID
var timeoutID = scope.setTimeout(function[, delay, arg1, arg2, ...]);
var timeoutID = scope.setTimeout(function[, delay]);
var timeoutID = scope.setTimeout(code[, delay]);
https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/setTimeout
clearTimeout
scope.clearTimeout(timeoutID)
https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/clearTimeout
setInterval
intervalID
var intervalID = scope.setInterval(func, [delay, arg1, arg2, ...]);
var intervalID = scope.setInterval(function[, delay]);
var intervalID = scope.setInterval(code, [delay]);
https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/setInterval
clearInterval
scope.clearInterval(intervalID)
https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/clearInterval
prototype
setTimeout(() => log(`zero`), 1000);
// 204
// zero
window[204];
// undefined
clearInterval;
// ƒ clearInterval() { [native code] }
clearInterval.__proto__;
// ƒ () { [native code] }
clearInterval.__proto__.prototype;
// undefined
clearInterval.__proto__.constructor;
// ƒ Function() { [native code] }
typeof clearInterval;
// "function"
Object.prototype.toString(clearInterval);
// "[object Object]"
clearInterval instanceof Object;
// true
How to clear all Timeouts in JavaScript
"use strict";
/**
*
* @author xgqfrms
* @license MIT
* @copyright xgqfrms
* @created 2020-07-27
* @modified
*
* @description createClearAllTimeouts
* @difficulty Easy Medium Hard
* @complexity O(n)
* @augments
* @example
* @link
* @solutions
*
*/
const log = console.log;
class createClearAllTimeouts {
constructor(name) {
this.name = name;
// this.ids = [];
}
// ids = [];
static ids = [];
static add(callback, timeout) {
const id = setTimeout(() => {
callback();
}, timeout);
console.log(`add id`, id);
this.ids.push(id);
// Uncaught TypeError: Cannot read property 'push' of undefined
}
static clearAll() {
const arr = this.ids;
let len = this.ids.length;
while (len > 0) {
const id = arr[len - 1];
console.log(`clear id`, id);
clearTimeout(id);
len--;
}
}
};
createClearAllTimeouts.add(() => console.log(`1`), 0)
createClearAllTimeouts.add(() => console.log(`2`), 0)
createClearAllTimeouts.add(() => console.log(`3`), 0)
createClearAllTimeouts.clearAll();

clearAllSetTimeouts
"use strict";
/**
*
* @author xgqfrms
* @license MIT
* @copyright xgqfrms
* @created 2020-07-27
* @modified
*
* @description clearAllSetTimeouts
* @difficulty Easy Medium Hard
* @complexity O(n)
* @augments
* @example
* @link
* @solutions
*
*/
const log = console.log;
class clearAllSetTimeouts {
constructor(name) {
this.name = name;
}
static ids = [];
static add(callback, timeout) {
const id = setTimeout(() => {
callback();
}, timeout);
log(`add id`, id);
this.ids.push(id);
}
static clearAll() {
const arr = this.ids;
let len = this.ids.length;
while (len > 0) {
const id = arr[len - 1];
log(`clear id`, id);
clearTimeout(id);
len--;
}
}
};
// test
clearAllSetTimeouts.add(() => log(`1`), 0)
clearAllSetTimeouts.add(() => log(`2`), 0)
clearAllSetTimeouts.add(() => log(`3`), 0)
clearAllSetTimeouts.clearAll();

function createClearAllTimeouts() {
const noop = () => {};
let firstId = setTimeout(noop, 0);
return () => {
const lastId = setTimeout(noop, 0);
while (firstId !== lastId) {
firstId += 1;
clearTimeout(firstId);
}
};
};
const clearAllTimeouts = createClearAllTimeouts();
setTimeout(() => {
console.log('Should never show 4');
}, 300);
setTimeout(() => {
console.log('Should never show 5');
}, 400);
clearAllTimeouts();
https://obscurejavascript.tumblr.com/post/183031058225/how-to-clear-all-timeouts-in-javascript
https://stackoverflow.com/questions/8860188/javascript-clear-all-timeouts/16440036
https://stackoverflow.com/questions/858619/viewing-all-the-timeouts-intervals-in-javascript
https://stackoverflow.com/a/8345814
https://www.sitepoint.com/clear-setinterval-knowing-id/
https://github.com/nodejs/help/issues/174
promise
https://stackoverflow.com/questions/58667357/set-timeout-in-chrome-debugger-tools
print finished
https://developer.mozilla.org/en-US/docs/Web/API/WindowEventHandlers/onafterprint
window.addEventListener("afterprint", function(event) { ... });
window.onafterprint = function(event) { ... };
https://stackoverflow.com/questions/18325025/how-to-detect-window-print-finish
refs
xgqfrms 2012-2020
www.cnblogs.com 发布文章使用:只允许注册用户才可以访问!
what's the print number means after called the setTimeout function in Chrome console?的更多相关文章
- What a version number means
http://stackoverflow.com/questions/3768261/best-practices-guidance-for-maintaining-assembly-version- ...
- print number
# -*- coding: utf-8 -*-"""------------------------------------------------- File Name ...
- JavaScript数据结构和算法----队列
前言 队列和栈很像,只是用了不同的原则.队列是遵循先进先出(FIFO)原则的一组有序的的项,队列在尾部添加新元素,从顶部移除元素.最新添加的元素必须必须排队在队列的,末尾.可以想象食堂排队买饭的样子. ...
- 深入理解定时器系列第一篇——理解setTimeout和setInterval
× 目录 [1]setTimeout [2]setInterval [3]运行机制[4]作用[5]应用 前面的话 很长时间以来,定时器一直是javascript动画的核心技术.但是,关于定时器,人们通 ...
- setTimeout和setInterval从入门到精通
我们在日常web前端开发中,经常需要用到定时器方法. 前端中的定时器方法是浏览器提供的,并不是ECMAScript规范中的.是window对象的方法. 浏览器中的定时器有两种, 一种是每间隔一定时间执 ...
- 理解javascript中的浏览器窗口——窗口基本操作
× 目录 [1]窗口位置 [2]窗口大小 [3]打开窗口[4]关闭窗口 前面的话 BOM全称是brower object model(浏览器对象模型),主要用于管理窗口及窗口间的通讯,其核心对象是wi ...
- js调用页面打印
----------------------调用页面打印-------------------------------- <body> <div id="divPrint& ...
- [转]七天学会NodeJS
转:http://nqdeng.github.io/7-days-nodejs/ NodeJS基础 什么是NodeJS JS是脚本语言,脚本语言都需要一个解析器才能运行.对于写在HTML页面里的JS, ...
- 你所不了解的setTimeout
看到了一篇不错的文章<你会用setTimeout吗 >,转载过来的,改了个名字,一下子感觉搞大上了,嘎嘎. 加了几个关于 setTimeout 和setInterval的小知识: 关于se ...
随机推荐
- pywin32 pywin32 docx文档转html页面 word doc docx 提取文字 图片 html 结构
https://blog.csdn.net/X21214054/article/details/78873338# python docx文档转html页面 - 程序猿tx - 博客园 https:/ ...
- Language Guide (proto3) | proto3 语言指南(十二)定义服务
Defining Services - 定义服务 如果要在RPC(Remote Procedure Call,远程过程调用)系统中使用消息类型,可以在.proto文件中定义RPC服务接口,协议缓冲区编 ...
- Java——对象和类
对象:类的一个实例,有状态和行为. 类:一个模板,描述一类对象行为和状态. Java中的对象 对象具有状态和行为.对象的状态就是属性,行为通过方法体现. 在开发中,方法操作对象内部状态的改变,对象的相 ...
- linux最初配置( vimrc设置 、tab键设置 inputrc、中文输入法等等)
1..vimrc设置 syntax on set tabstop=4 set softtabstop=4 set autoindent set cindent set nu set ruler & ...
- Commons Collections1分析
0x01.基础知识铺垫 接下来这个过程将涉及到几个接口和类 1.LazyMap 我们通过下⾯这⾏代码对innerMap进⾏修饰,传出的outerMap即是修饰后的Map: Map outerMap = ...
- 小白搭建WAMP详细教程---mysql安装与设置
MySQL分为安装版和解压版.为了以后MySQL出问题想重装时会出现各种不必要的麻烦,我们这里选择解压版MySQL.详细步骤如下: 一:Mysql官网下载Mysql解压版 到官网下载,网址为:http ...
- Pytest(7)自定义用例顺序pytest-ordering
前言 测试用例在设计的时候,我们一般要求不要有先后顺序,用例是可以打乱了执行的,这样才能达到测试的效果. 有些同学在写用例的时候,用例写了先后顺序, 有先后顺序后,后面还会有新的问题(如:上个用例返回 ...
- C - Door Man(欧拉回路_格式控制)
现在你是一个豪宅的管家,因为你有个粗心的主人,所以需要你来帮忙管理,输入会告诉你现在一共有多少个房间,然后会告诉你从哪个房间出发,你的任务就是从出发的房间通过各个房间之间的通道,来把所有的门都关上,然 ...
- B - B(Is It A Tree?)
给出一堆边给你,让你判断这是不是一棵树.边的信息以(start , end)的形式给出. A tree is a well-known data structure that is either em ...
- Codeforces Round #625 (Div. 2, based on Technocup 2020 Final Round) D. Navigation System(有向图,BFS,最短路)
题意: n 点 m 边有向图,给出行走路径,求行走途中到路径终点最短路变化次数的最小值和最大值 . 思路 : 逆向广搜,正向模拟. #include <bits/stdc++.h> usi ...