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 ...
随机推荐
- IDEA SSM后端框架入门
SSM框架 如果对SSM一无所知,推荐先去看这本书,可以在微信读书上看. 知识点 控制器返回对象时,对象需要有getter,setter方法,才能自动转化为json数据类型. 一个服务管理者对应多个业 ...
- node集群(cluster)
使用例子 为了让node应用能够在多核服务器中提高性能,node提供cluster API,用于创建多个工作进程,然后由这些工作进程并行处理请求. // master.js const cluster ...
- SRE SLO On-Call 流程机制 系统稳定性
开篇词|SRE是解决系统稳定性问题的灵丹妙药吗? https://time.geekbang.org/column/article/212686 这两年,近距离地接触了很多不同类型.不同规模的企业 I ...
- LDAP学习
.top pre { display: block; background: rgba(68, 67, 65, 1); color: rgba(255, 255, 255, 1); margin: 1 ...
- flutter--Dart基础语法(一)
一.前言 Flutter 是 Google 开源的 UI 工具包,帮助开发者通过一套代码库高效构建多平台精美应用,Flutter 开源.免费,拥有宽松的开源协议,支持移动.Web.桌面和嵌入式平台. ...
- Spring Boot RestTemplate文件上传
@ResponseBody @RequestMapping(value = "/upload.do", method = RequestMethod.POST) public St ...
- (26)Vim 2
1.Vim 查找文本 /abc 从光标所在位置向前查找字符串 abc /^abc 查找以 abc 为行首的行 /abc$ 查找以 abc 为行尾的行 ?abc 从光标所在为主向后查找字符串 abc n ...
- P1714 切蛋糕 dp+单调队列
题意: 题目描述 在幻想乡,琪露诺是以笨蛋闻名的冰之妖精. 某一天,琪露诺又在玩速冻青蛙,就是用冰把青蛙瞬间冻起来.但是这只青蛙比以往的要聪明许多,在琪露诺来之前就已经跑到了河的对岸.于是琪露诺决定到 ...
- P1435 回文字串(DP)
题目描述 回文词是一种对称的字符串.任意给定一个字符串,通过插入若干字符,都可以变成回文词.此题的任务是,求出将给定字符串变成回文词所需要插入的最少字符数. 比如 "Ab3bd"插 ...
- SPF POJ - 1523 割点+并查集
题意: 问你这个图中哪个点是割点,如果把这个点去掉会有几个子网 代码: 1 //给你几个点,用着几个点形成了一个图.输入边形成的图,问你这个图中有多少个割点.每一个割点去掉后会形成几个强连通分量 2 ...