随笔分类 -  Javascript

上一页 1 ··· 4 5 6 7 8 9 10 11 12 ··· 31 下一页
摘要: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 阅读(71) 评论(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 阅读(38) 评论(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 阅读(38) 评论(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 阅读(31) 评论(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 阅读(23) 评论(0) 推荐(0)
摘要:In JavaScript, the factory pattern isn't much more than a function that returns an object without using the new keyword. ES6 arrow functions allow us 阅读全文
posted @ 2022-08-26 17:44 Zhentiw 阅读(32) 评论(0) 推荐(0)
摘要:Source: https://javascriptpatterns.vercel.app/patterns/design-patterns/singleton-pattern With the Singleton Pattern, we restrict the instantiation of 阅读全文
posted @ 2022-08-26 15:44 Zhentiw 阅读(30) 评论(0) 推荐(0)
摘要:Module pattern provide a way to have both public and private pieces with the export keyword. This protects values from leaking into the global scope o 阅读全文
posted @ 2022-08-26 15:18 Zhentiw 阅读(40) 评论(0) 推荐(0)
摘要:Blog: https://www.geeksforgeeks.org/es6-trampoline-function/ Stackoverflow problem for recursion: const sumBelow = (number, sum = 0) => ( number 0 ? s 阅读全文
posted @ 2022-08-18 14:32 Zhentiw 阅读(55) 评论(0) 推荐(0)
摘要:function lotteryNum() { return (Math.round(Math.random() * 100) % 58) + 1; } function recordNumber(luckLotteryNumbers: readonly number[], num: number) 阅读全文
posted @ 2022-08-15 19:13 Zhentiw 阅读(22) 评论(0) 推荐(0)
摘要:String in Javascript is immutable. Means that once they were created, they cannot be modified. This also means that simple operations like appending a 阅读全文
posted @ 2022-07-13 01:16 Zhentiw 阅读(59) 评论(0) 推荐(0)
摘要:function swap(array, i, j) { const [item] = array.splice(i, 1) // get item and remove this item from array array.splice(j, 0, item) } 阅读全文
posted @ 2022-07-10 21:14 Zhentiw 阅读(36) 评论(0) 推荐(0)
摘要:Sometimes one line of code can eliminate 50% of your bundle size. As you'll see in this video, we can remove "dead code" from modules we are working w 阅读全文
posted @ 2022-05-01 21:54 Zhentiw 阅读(47) 评论(0) 推荐(0)
摘要:This lessons builds on Build lodash.debounce from scratch to add support for one of its more interesting options: maxWait. The maxWait option ensures 阅读全文
posted @ 2022-04-11 01:42 Zhentiw 阅读(97) 评论(0) 推荐(0)
摘要:This lesson will demonstrate how to recreate a simplified version of the popular lodash.debounce method from scratch. I literally failed a job intervi 阅读全文
posted @ 2022-04-11 01:30 Zhentiw 阅读(82) 评论(0) 推荐(0)
摘要:This lesson will demonstrate how to recreate a simplified version of the popular lodash.merge method from scratch. First we'll create a test file with 阅读全文
posted @ 2022-04-11 01:15 Zhentiw 阅读(117) 评论(0) 推荐(0)
摘要:// ❎ const object = {} object[key] = value // 👍 better performance const map = new Map() map.set(key, value) 阅读全文
posted @ 2022-03-30 15:10 Zhentiw 阅读(64) 评论(0) 推荐(0)
摘要:const b = true const c = false let object = { a: 1, ...(b ? {b: 2}: {}), ...(c ? {c: 3}: {}) }; console.log(object) // { a: 1, b: 2 } 阅读全文
posted @ 2022-03-28 13:51 Zhentiw 阅读(35) 评论(0) 推荐(0)
摘要:const getGlobalThis = () => { if (typeof self !== 'undefined') return self if (typeof window !== 'undefined') return window if (typeof global !== 'und 阅读全文
posted @ 2022-03-14 15:16 Zhentiw 阅读(43) 评论(0) 推荐(0)
摘要:Add functionality to objects or classes without inheritance Although we can add functionality iwht mixins without inheritance, mixins themselves can u 阅读全文
posted @ 2022-02-08 02:08 Zhentiw 阅读(42) 评论(0) 推荐(0)

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