随笔分类 - Javascript
摘要:The key differences between CommonJS (CJS) and ECMAScript Modules (ESM) come down to their execution model. CommonJS (CJS) Synchronous: Each require()
阅读全文
摘要:AJAX 就是指在web应用程序中异步向服务器发送请求。 它的实现方式有两种,XMLHttpRequest 简称XHR和Fetch 以下是两者的对比 功能点 XHR Fetch 基本的请求能力 ✅ ✅ 基本的获取响应能力 ✅ ✅ 监控请求进度 ✅ ❌ 监控响应进度 ✅ ✅ Service Worke
阅读全文
摘要:我们已经将我们的代码开源到了 github 上面,但是如果是其他开发者想要使用我们的库,还需要去 github 上面手动下载下来,添加到他们的项目里面,这样是非常低效的一种方式。 npm 的出现解决了这个问题,npm 是前端领域非常出名的一个包的托管平台,提供了代码的托管和检索以及下载安装功能。 注
阅读全文
摘要:本小节我们先来介绍一下在设计开源库的时候有哪些原则以及最佳实践。 函数的设计 函数包含三要素: 函数名 参数 返回值 函数名 函数通常表示做一件事情,因此函数名一般为一个动词或者表示动作的短语,我们希望通过函数名就能够传达这个函数是做什么的。哪怕整个函数单词用得多一些,整个函数名长一些也无所谓,只要
阅读全文
摘要:In this lesson, you'll learn how to implement smooth state transitions in your web applications using the browser's built-in View Transitions API. We'
阅读全文
摘要:var a = { n: 1 }; var b = a; a.x = a = { n: 2 }; console.log(a.x); // undefined console.log(b.x); // {n: 2} Javascript see the following code, mainly
阅读全文
摘要:Write big number // NOT 100000 // Better 100_000 1e5 Shorthands syntax for floating number // Normal 0.123 // The same .123 // eX also apply to floati
阅读全文
摘要:Example 1 Before function addEvent(ele, eventName, handler) { if (ele.addEventListener) { ele.addEventListener(eventName, handler); } else if (ele.att
阅读全文
摘要:let _globalThis: any export const getGlobalThis = (): any => { return ( _globalThis || (_globalThis = typeof globalThis !== 'undefined' ? globalThis :
阅读全文
摘要:== 从上到下按照规则比较,直到能够得到确切结果为止:1. 两端存在 NaN,返回 false2. undefined 和 null 只有与自身比较,或者互相比较时,才会返回 true,和其他原始类型比较返回 false3. 两端类型相同,比较值4. 两端都是原始类型,转换成数字重新比较 5. 一端
阅读全文
摘要:U+200B: Zero-width space Used for soft line breaks in long words. U+FEFF: Zero-width non-breaking space Prevents line breaks at specific positions. U+
阅读全文
摘要:Virtual DOM Advantage: One of the advantages of the virtual DOM is cross-platform rendering abstraction. The virtual DOM can connect to different host
阅读全文
摘要:When you run node.js you can run node --expose-gc index.js Which will allow you manully cleanup gc: global.gc() Map For map, it is easy to cost memory
阅读全文
摘要:For example you have nested for loop, and from inner most for loop you want to break not just inner loop but also outmost for loop how to do that? We
阅读全文
摘要:We have a module: const key = Symbol('key') export class A { [key] = 1 value () { console.log(this[key]) } } It seems that keyis not expose to outside
阅读全文
摘要:function main() { const datas = new Array(10000).fill(null).map((_, i) => i) function taskHanlder(_, i) { console.log(i) } performChunkNode(datas, tas
阅读全文
摘要:When attempting to load the same module twice in JavaScript you'll hit a cache and code won't re-run. In scenarios where you actually do want to have
阅读全文
摘要:During the past, this was a working solution function isArray(obj) { return Object.prototype.toString.call(obj) '[object Array]' } But now it doesn't
阅读全文
摘要:What's the output of following code: let a = 1; const b = a + ++a * a++; In Javascript, the code always run from lef to right. Both ++aand a++ are exp
阅读全文
摘要:Why? Mainly due to undefinedis not a keyword, therefore you are able to create a variable called undefinedand assign it any value let undefined = 10 A
阅读全文