随笔分类 -  Javascript

上一页 1 ··· 3 4 5 6 7 8 9 10 11 ··· 31 下一页
摘要:button.addEventListener( 'click', (event) => { console.log('listener 1') queueMicrotask(() => { console.log('microtask') }) } ) button.addEventListene 阅读全文
posted @ 2023-06-02 20:59 Zhentiw 阅读(22) 评论(0) 推荐(0)
摘要:You can use getEventListeners(button)directly inside chrome devtool, but not inside application code. You can use monitorEvents(button, 'keydown'), no 阅读全文
posted @ 2023-06-02 20:51 Zhentiw 阅读(21) 评论(0) 推荐(0)
摘要:Difference between yieldand return returnset doneto true /** * Example 1 */ function* loggerator() { console.log("running"); yield "paused"; console.l 阅读全文
posted @ 2023-05-25 17:39 Zhentiw 阅读(12) 评论(0) 推荐(0)
摘要:Blog: https://dev.to/marclipovsky/discovering-the-power-of-javascript-proxy-after-all-this-time-4627 Lazy loading: const lazyLoadHandler = { get: func 阅读全文
posted @ 2023-05-04 13:45 Zhentiw 阅读(27) 评论(0) 推荐(0)
摘要:reverse()mutates the original array, return the reference point to the original array. The toReversed() method of Array instances is the copying count 阅读全文
posted @ 2023-05-02 14:06 Zhentiw 阅读(30) 评论(0) 推荐(0)
摘要:sort(), mutates the original array, and return the reference to original array and sorted. The toSorted() method of Array instances is the copying ver 阅读全文
posted @ 2023-05-02 14:04 Zhentiw 阅读(56) 评论(0) 推荐(0)
摘要:Array.prototype.splice()mutates the original array. To avoid mutation, we use Array.prototype.slice(). new method Array.prototype.toSpliced() return a 阅读全文
posted @ 2023-05-02 14:01 Zhentiw 阅读(90) 评论(0) 推荐(0)
摘要: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' 阅读全文
posted @ 2023-05-02 13:55 Zhentiw 阅读(45) 评论(0) 推荐(0)
摘要:Both JSON.parse(JSON,strigify())& structuredClone doesn't work with Dateand function. var foo = {name: 'foo', bar: () => 'bar'} var foo2 = structuredC 阅读全文
posted @ 2023-04-18 13:36 Zhentiw 阅读(68) 评论(0) 推荐(0)
摘要: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 阅读全文
posted @ 2023-04-07 19:58 Zhentiw 阅读(32) 评论(0) 推荐(0)
摘要:// Initialize a 2D array with zeros const str1 = "Hello" const str2 = "World" const dp = Array.from({ length: str1.length }, () => Array.from({ length 阅读全文
posted @ 2023-03-28 14:30 Zhentiw 阅读(27) 评论(0) 推荐(0)
摘要:const rtf = new Intl.RelativeTimeFormat( navigator.language ) const res = rtf.format(-2, 'day') console.log(res) // "2 days ago" 阅读全文
posted @ 2023-03-16 15:31 Zhentiw 阅读(23) 评论(0) 推荐(0)
摘要:const calendarEvent = { title: 'abc submit', date: new Date(123), attendees: ["Steve", {name: 'Steve'}] } const copied = structuredClone(calendarEvent 阅读全文
posted @ 2023-03-16 15:18 Zhentiw 阅读(41) 评论(0) 推荐(0)
摘要: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 阅读全文
posted @ 2023-02-21 16:08 Zhentiw 阅读(25) 评论(0) 推荐(0)
摘要: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 阅读全文
posted @ 2023-02-20 15:07 Zhentiw 阅读(28) 评论(0) 推荐(0)
摘要:Binding to Media Events import './assets/css/style.css'; import autumnMp4 from './assets/media/autumn.mp4'; const app = document.getElementById('app') 阅读全文
posted @ 2023-01-02 01:59 Zhentiw 阅读(32) 评论(0) 推荐(0)
摘要: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}, (_, 阅读全文
posted @ 2022-12-25 20:21 Zhentiw 阅读(102) 评论(0) 推荐(0)
摘要:The Intl.Collator object enables language-sensitive string comparison. console.log(['Z', 'a', 'z', 'ä'].sort(new Intl.Collator('de').compare)); // exp 阅读全文
posted @ 2022-12-25 20:03 Zhentiw 阅读(74) 评论(0) 推荐(0)
摘要:Since arrays are objects, we can destructure their indexes to easily grab the first and last itmes const bikes = ['bianchi', 'miele', 'miyata', 'benot 阅读全文
posted @ 2022-12-25 19:59 Zhentiw 阅读(26) 评论(0) 推荐(0)
摘要: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 阅读全文
posted @ 2022-12-15 20:39 Zhentiw 阅读(642) 评论(0) 推荐(0)

上一页 1 ··· 3 4 5 6 7 8 9 10 11 ··· 31 下一页