随笔分类 - Javascript
摘要: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
阅读全文
摘要:It is not good to import axios from each Components or different services, because it will create a new instance of axios everytime. import axios from
阅读全文
摘要:Main difference is that in keyword will check on object prototype chain as well but hasOwnProperty won't check agaist prototype chain const obj = {} '
阅读全文
摘要:Let's see the following code function copyText(text) { if (navigator.clipboard) { navigator.clipboard.writeText(text); } else { const input = document
阅读全文
摘要:The Reflect namespace object contains static methods for invoking interceptable JavaScript object internal methods. The methods are the same as those
阅读全文
摘要:const [a, b] = { a: 3, b: 4, }; console.log(a, b); // TypeError: {(intermediate value)(intermediate value)} is not iterable How to make it work withou
阅读全文