随笔分类 - Javascript
摘要:button.addEventListener( 'click', (event) => { console.log('listener 1') queueMicrotask(() => { console.log('microtask') }) } ) button.addEventListene
阅读全文
摘要:You can use getEventListeners(button)directly inside chrome devtool, but not inside application code. You can use monitorEvents(button, 'keydown'), no
阅读全文
摘要:Difference between yieldand return returnset doneto true /** * Example 1 */ function* loggerator() { console.log("running"); yield "paused"; console.l
阅读全文
摘要:Blog: https://dev.to/marclipovsky/discovering-the-power-of-javascript-proxy-after-all-this-time-4627 Lazy loading: const lazyLoadHandler = { get: func
阅读全文
摘要:reverse()mutates the original array, return the reference point to the original array. The toReversed() method of Array instances is the copying count
阅读全文
摘要:sort(), mutates the original array, and return the reference to original array and sorted. The toSorted() method of Array instances is the copying ver
阅读全文
摘要:Array.prototype.splice()mutates the original array. To avoid mutation, we use Array.prototype.slice(). new method Array.prototype.toSpliced() return a
阅读全文
摘要:Prevously, when we want to upate an item inside a array: const items = [ {id: 1, name: 'a'}, {id: 2, name: 'b'}, {id: 3, name: 'c'}, {id: 4, name: 'd'
阅读全文
摘要:Both JSON.parse(JSON,strigify())& structuredClone doesn't work with Dateand function. var foo = {name: 'foo', bar: () => 'bar'} var foo2 = structuredC
阅读全文
摘要:Compare two code snippet const people = [ {id: 1,name: 'John', age: 45}, {id: 2,name: "Op", age: 32}, {id: 3, name: "Wade",age: 39 } ] // option 1 con
阅读全文
摘要:// Initialize a 2D array with zeros const str1 = "Hello" const str2 = "World" const dp = Array.from({ length: str1.length }, () => Array.from({ length
阅读全文
摘要:const rtf = new Intl.RelativeTimeFormat( navigator.language ) const res = rtf.format(-2, 'day') console.log(res) // "2 days ago"
阅读全文
摘要:const calendarEvent = { title: 'abc submit', date: new Date(123), attendees: ["Steve", {name: 'Steve'}] } const copied = structuredClone(calendarEvent
阅读全文
摘要:In Javascript, if you are using Object to store key-valeu pairs while you will be adding and deleting keys frequently, then you should use Map instead
阅读全文
摘要:Promise.all: Problem: let's say we have two promises, P1, P2, P1 reject in 1s, and P2 reject in 3s. What will happen in catch block? It only able to c
阅读全文
摘要:Binding to Media Events import './assets/css/style.css'; import autumnMp4 from './assets/media/autumn.mp4'; const app = document.getElementById('app')
阅读全文
摘要:Array.from() is a great way to chunk up arrays because of the secondary argument being a map function. const hugeArray = Array.from({length: 76}, (_,
阅读全文
摘要:The Intl.Collator object enables language-sensitive string comparison. console.log(['Z', 'a', 'z', 'ä'].sort(new Intl.Collator('de').compare)); // exp
阅读全文
摘要:Since arrays are objects, we can destructure their indexes to easily grab the first and last itmes const bikes = ['bianchi', 'miele', 'miyata', 'benot
阅读全文
摘要:It is useful to enable '@typescript-eslint/unbound-method': 'error', because this kind of error is related to this keyword, sometime it is hard to not
阅读全文

浙公网安备 33010602011771号