随笔分类 - js
摘要:var element = new Image(); Object.defineProperty(element, "id", { get: function () { debugger; }, }); requestAnimationFrame(function check() { console
阅读全文
摘要:使用创建style的方式 btn.addEventListener("click", async () => { const ns = document.createElement("style"); ns.textContent = ` button { color: red; } `; docu
阅读全文
摘要:在表单提交前修改数据,此事件在submit之后 f1.addEventListener("formdata", (e) => { e.formData.append("phone", "xxx"); })
阅读全文
摘要:btn.addEventListener("click", async () => { try { const state = await Notification.requestPermission(); if (state !== "granted") { // Need to request
阅读全文
摘要:let lock; btn.addEventListener("click", async () => { try { if (lock) { lock.release(); return; } lock = await navigator.wakeLock.request("screen"); l
阅读全文
摘要:选择文件,获取文件句柄 btn.addEventListener("click", async (e) => { try { const hFiles = await window.showOpenFilePicker({ types: [ { description: "文本文件", accept
阅读全文
摘要:function hookSend(hook) { if (!XMLHttpRequest.prototype._oldSend) XMLHttpRequest.prototype._oldSend = XMLHttpRequest.prototype.send; XMLHttpRequest.pr
阅读全文
摘要:原文 定义掩码 const mask0 = parseInt("00000001", 2); const mask1 = parseInt("00000010", 2); const mask2 = parseInt("00000100", 2); const mask3 = parseInt("0
阅读全文
摘要:for (let i = 0; i < 3; i++) { console.log(i); } let i = 0; for (;;) { if (!(i < 3)) { break; } console.log(i); i++; } 添加label end: for (let i = 0; i <
阅读全文
摘要:https://www.npmjs.com/package/xlsx 安装依赖 npm install xlsx Example import * as XLSX from "xlsx"; export const Sheet1 = "Sheet1"; export const Sheet2 = "
阅读全文
摘要:<button id="btn1">长按触发</button> <button id="btn2">长按触发2</button> interface IOpt { el: HTMLElement; listener: EventListener; options?: boolean | AddEve
阅读全文
摘要:function co<T>(fn: () => Generator<any, any, any>): Promise<T> { const g: Generator = fn(); return new Promise((resolve, reject) => { const r = g.next
阅读全文
摘要:let _subscriber: any; function autorun(subscriber: Function) { _subscriber = subscriber; _subscriber(); _subscriber = null; } class Observer { #list:
阅读全文
摘要:灵感来自此博客和此库 index.html <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scal
阅读全文
摘要:1: 使用reject function hello() { let _res, _rej: any; const promise = new Promise((res, rej) => { _res = res; _rej = rej; setTimeout(() => { res("hello
阅读全文
摘要:"mdn" ts const rx_one = /^[\],:{}\s] $/; const rx_two = /\\(?:["\\\/bfnrt]|u[0 9a fA F]{4})/g; // 匹配合法json符号 // "asd" or 1.23 or 1.3e4 or 1.3e 4 or 1.
阅读全文
摘要:"astexplorer" "babel types" code to ast js const { parse } = babel; const code = ` for (let k in ${data}) { let ${path.__cxt} = _setCxt(k, ${data}); }
阅读全文
摘要:myEval export const evalExp = /[!\&\|\+\-\*\%=\/<\>\^\(\)\~\:\?\;]/g; export function myEval(originString: string, context: any) { if (!context) retur
阅读全文

浙公网安备 33010602011771号