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

https://stackoverflow.com/questions/3141064/how-to-stop-all-timeouts-and-intervals-using-javascript/8345814#8345814



xgqfrms 2012-2020

www.cnblogs.com 发布文章使用:只允许注册用户才可以访问!


what's the print number means after called the setTimeout function in Chrome console?的更多相关文章

  1. What a version number means

    http://stackoverflow.com/questions/3768261/best-practices-guidance-for-maintaining-assembly-version- ...

  2. print number

    # -*- coding: utf-8 -*-"""------------------------------------------------- File Name ...

  3. JavaScript数据结构和算法----队列

    前言 队列和栈很像,只是用了不同的原则.队列是遵循先进先出(FIFO)原则的一组有序的的项,队列在尾部添加新元素,从顶部移除元素.最新添加的元素必须必须排队在队列的,末尾.可以想象食堂排队买饭的样子. ...

  4. 深入理解定时器系列第一篇——理解setTimeout和setInterval

    × 目录 [1]setTimeout [2]setInterval [3]运行机制[4]作用[5]应用 前面的话 很长时间以来,定时器一直是javascript动画的核心技术.但是,关于定时器,人们通 ...

  5. setTimeout和setInterval从入门到精通

    我们在日常web前端开发中,经常需要用到定时器方法. 前端中的定时器方法是浏览器提供的,并不是ECMAScript规范中的.是window对象的方法. 浏览器中的定时器有两种, 一种是每间隔一定时间执 ...

  6. 理解javascript中的浏览器窗口——窗口基本操作

    × 目录 [1]窗口位置 [2]窗口大小 [3]打开窗口[4]关闭窗口 前面的话 BOM全称是brower object model(浏览器对象模型),主要用于管理窗口及窗口间的通讯,其核心对象是wi ...

  7. js调用页面打印

    ----------------------调用页面打印-------------------------------- <body> <div id="divPrint& ...

  8. [转]七天学会NodeJS

    转:http://nqdeng.github.io/7-days-nodejs/ NodeJS基础 什么是NodeJS JS是脚本语言,脚本语言都需要一个解析器才能运行.对于写在HTML页面里的JS, ...

  9. 你所不了解的setTimeout

    看到了一篇不错的文章<你会用setTimeout吗 >,转载过来的,改了个名字,一下子感觉搞大上了,嘎嘎. 加了几个关于 setTimeout 和setInterval的小知识: 关于se ...

随机推荐

  1. unstable sort

    $sort (aggregation) - MongoDB Manual https://docs.mongodb.com/manual/reference/operator/aggregation/ ...

  2. Mysql 四种事务隔离级别

    一.前提 时过一年重新拾起博文记录,希望后面都能坚持下来. 接着之前MySql的学习,先记录下这篇. 以下都是基于mysql8 innodb存储引擎进行分析的. 二.事务的ACID特性 A(Atomi ...

  3. java.lang.IllegalStateException Unable to find a @SpringBootConfiguration错误解决方案

    问题描述:java.lang.IllegalStateException: Unable to find a @SpringBootConfiguration, you need to use @Co ...

  4. codevs 1344 模拟退火

    1344 线型网络  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 钻石 Diamo   题目描述 Description 有 N ( <=20 ) 台 PC 放在机房内 ...

  5. springboot+Jenkins+docker-compose自动部署项目实践

    DevOps思想 一个开发.测试.运维的整个过程的思想. plan:需求.计划 code:编码 build:构建 test: 测试 release:发布版本 deploy:部署 operate:项目运 ...

  6. 上海某小公司面试题:Java线程池来聊聊

    <对线面试官>系列目前已经连载11篇啦!进度是一周更新两篇,欢迎持续关注 [对线面试官]Java注解 [对线面试官]Java泛型 [对线面试官] Java NIO [对线面试官]Java反 ...

  7. CCF CSP 202009-1 称检查点查询

    202009-1 称检查点查询 题目背景 2020年6月8日,国务院联防联控机制发布<关于加快推进新冠病毒核酸检测的实施意见>,提出对"密切接触者"等八类重点人群&qu ...

  8. NodeMCU获取并解析心知天气信息

    NodeMCU获取并解析心知天气信息 1 注册心知天气并获取私钥 打开心知天气网站,点击注册按钮 填写基本信息注册心知天气账号,登录注册所填写的邮箱点击链接进行账号激活,随后出现如下界面 点击登录按钮 ...

  9. Flink-v1.12官方网站翻译-P002-Fraud Detection with the DataStream API

    使用DataStream API进行欺诈检测 Apache Flink提供了一个DataStream API,用于构建强大的.有状态的流式应用.它提供了对状态和时间的精细控制,这使得高级事件驱动系统的 ...

  10. 《Proxy系列专题》:代理模式(静态、JDK、CGLib)

    <Proxy系列专题>:代理模式(静态.JDK.CGLib)使用 现象:在如今互联网时代,项目的复杂度不断的提升,有些场景下需要一定的设计优化来支撑业务的扩展,如为了不改动原始类,但需要对 ...