随笔分类 - Javascript
摘要:The optimizing compiler optimizes for what it’s seen. If it sees something new, that’s problematic. Seleting properties has some strange implications
阅读全文
摘要:Code: benchmark.js const { performance } = require('perf_hooks'); // SETUP 🏁 let iterations = 1e7; const a = 1; const b = 2; const add = (x, y) => x
阅读全文
摘要:function countBehavior(state, event) { if (event.type "INC") { return { ...state, count: state.count + 1 } } } function createActor(behavior, initialS
阅读全文
摘要: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
阅读全文
摘要:Source: https://javascriptpatterns.vercel.app/patterns/design-patterns/prototype-pattern If you use factory pattern to create object: const createDog
阅读全文
摘要: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
阅读全文
摘要:Source: https://javascriptpatterns.vercel.app/patterns/design-patterns/singleton-pattern With the Singleton Pattern, we restrict the instantiation of
阅读全文
摘要: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
阅读全文
摘要:Blog: https://www.geeksforgeeks.org/es6-trampoline-function/ Stackoverflow problem for recursion: const sumBelow = (number, sum = 0) => ( number 0 ? s
阅读全文
摘要:function lotteryNum() { return (Math.round(Math.random() * 100) % 58) + 1; } function recordNumber(luckLotteryNumbers: readonly number[], num: number)
阅读全文
摘要:String in Javascript is immutable. Means that once they were created, they cannot be modified. This also means that simple operations like appending a
阅读全文
摘要:function swap(array, i, j) { const [item] = array.splice(i, 1) // get item and remove this item from array array.splice(j, 0, item) }
阅读全文
摘要: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
阅读全文
摘要:This lessons builds on Build lodash.debounce from scratch to add support for one of its more interesting options: maxWait. The maxWait option ensures
阅读全文
摘要:This lesson will demonstrate how to recreate a simplified version of the popular lodash.debounce method from scratch. I literally failed a job intervi
阅读全文
摘要: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
阅读全文
摘要:// ❎ const object = {} object[key] = value // 👍 better performance const map = new Map() map.set(key, value)
阅读全文
摘要:const b = true const c = false let object = { a: 1, ...(b ? {b: 2}: {}), ...(c ? {c: 3}: {}) }; console.log(object) // { a: 1, b: 2 }
阅读全文
摘要:const getGlobalThis = () => { if (typeof self !== 'undefined') return self if (typeof window !== 'undefined') return window if (typeof global !== 'und
阅读全文
摘要:Add functionality to objects or classes without inheritance Although we can add functionality iwht mixins without inheritance, mixins themselves can u
阅读全文

浙公网安备 33010602011771号