随笔分类 -  Javascript

上一页 1 ··· 3 4 5 6 7 8 9 10 11 ··· 30 下一页
摘要: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 阅读(41) 评论(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 阅读(83) 评论(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 阅读(39) 评论(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 阅读(64) 评论(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 阅读(24) 评论(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 阅读(21) 评论(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 阅读(16) 评论(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 阅读(35) 评论(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 阅读(21) 评论(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 阅读(23) 评论(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 阅读(28) 评论(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 阅读(97) 评论(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 阅读(69) 评论(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 阅读(22) 评论(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 阅读(632) 评论(0) 推荐(0)
摘要:The optimizing compiler optimizes for what it’s seen. If it sees something new, that’s problematic. Seleting properties has some strange implications 阅读全文
posted @ 2022-12-03 23:11 Zhentiw 阅读(67) 评论(0) 推荐(0)
摘要:Code: benchmark.js const { performance } = require('perf_hooks'); // SETUP 🏁 let iterations = 1e7; const a = 1; const b = 2; const add = (x, y) => x 阅读全文
posted @ 2022-12-03 22:46 Zhentiw 阅读(33) 评论(0) 推荐(0)
摘要:function countBehavior(state, event) { if (event.type "INC") { return { ...state, count: state.count + 1 } } } function createActor(behavior, initialS 阅读全文
posted @ 2022-11-30 01:35 Zhentiw 阅读(35) 评论(0) 推荐(0)
摘要:Write a function that takes in an array of unique integers and returns an array of all permutations of those integers in no particular order. If the i 阅读全文
posted @ 2022-09-15 01:11 Zhentiw 阅读(27) 评论(0) 推荐(0)
摘要:Source: https://javascriptpatterns.vercel.app/patterns/design-patterns/prototype-pattern If you use factory pattern to create object: const createDog 阅读全文
posted @ 2022-08-26 18:09 Zhentiw 阅读(22) 评论(0) 推荐(0)

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