随笔分类 -  Javascript

上一页 1 ··· 4 5 6 7 8 9 10 11 12 ··· 30 下一页
摘要: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 阅读(26) 评论(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 阅读(27) 评论(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 阅读(39) 评论(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 阅读(51) 评论(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 阅读(21) 评论(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 阅读(57) 评论(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 阅读(35) 评论(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 阅读(45) 评论(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 阅读(89) 评论(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 阅读(76) 评论(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 阅读(115) 评论(0) 推荐(0)
摘要:// ❎ const object = {} object[key] = value // 👍 better performance const map = new Map() map.set(key, value) 阅读全文
posted @ 2022-03-30 15:10 Zhentiw 阅读(63) 评论(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 阅读(29) 评论(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 阅读(38) 评论(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 阅读(38) 评论(0) 推荐(0)
摘要:For example, we have a dropdown list, we want to keep "other" option always as last option. return options .sort((a, b) => { if (a.value == b.value) r 阅读全文
posted @ 2022-02-07 16:39 Zhentiw 阅读(43) 评论(0) 推荐(0)
摘要:Presnetational Component: A presentational compoentn receives its data through props. It's primary function is to simply display the data it receives 阅读全文
posted @ 2022-01-25 02:58 Zhentiw 阅读(56) 评论(0) 推荐(0)
摘要:Make data available to multiple child cpmpopnents to avoid prop drilling Create a Context: Hooks We can create a hook to provide context to components 阅读全文
posted @ 2022-01-23 16:46 Zhentiw 阅读(68) 评论(0) 推荐(0)
摘要:Share a single global insance throughout our application Proxies are a powerful way to add control over the behavior of an object. A proxy can have va 阅读全文
posted @ 2022-01-23 16:31 Zhentiw 阅读(44) 评论(0) 推荐(0)
摘要:const players = [ { id: 'x9Opl1', name: 'Mario', bio: 'Italian plumber and lead character', }, { id: '7fGlZ0', name: 'Luigi', bio: "Mario's green youn 阅读全文
posted @ 2021-12-15 17:03 Zhentiw 阅读(78) 评论(0) 推荐(0)

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