随笔分类 - Javascript
摘要: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
阅读全文
摘要:Presnetational Component: A presentational compoentn receives its data through props. It's primary function is to simply display the data it receives
阅读全文
摘要: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
阅读全文
摘要: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
阅读全文
摘要:const players = [ { id: 'x9Opl1', name: 'Mario', bio: 'Italian plumber and lead character', }, { id: '7fGlZ0', name: 'Luigi', bio: "Mario's green youn
阅读全文
摘要:const ary = [1, 2, 3, 4, 2, 3]; const unqiAry = (ary) => ary.filter((item, index) => ary.indexOf(item) index) unqiAry(ary) // [ 1, 2, 3, 4 ] const ary
阅读全文
摘要:let other = null console.log(other?.[0]) // undefined You can use optional chaining to access elements in an array. If the array is null or undefined,
阅读全文
摘要:The Event Delegation Pattern Event delegation is a simple, but powerful leveraging of the DOM event system which allows for easier adding of functiona
阅读全文
摘要:Object.is console.log(Object.is(2, 2)); // true console.log(Object.is({}, {})); // false Strict Equality: a b console.log(2 2); // true console.log({}
阅读全文
摘要:removeEventListener removes an event listener added with addEventListener. However, there are a number of gotchas to watch out for in order to correct
阅读全文
摘要:const items = [ 'Sojourner', 'Opportunity', 'Spirit', 'Curiosity', 'Perseverance', ] const formatter = new Intl.ListFormat('en', { style: 'long', type
阅读全文
摘要:Objects have the ability to use data and methods that other objects contain, as long as it lives on the [[prototype]] chain. In this lesson we’ll test
阅读全文
摘要:let getUrl = url => listener => { let controller = new AbortController() let signal = controller.signal fetch(url, {signal}) .then((response) => { ret
阅读全文
摘要:While using async/await, seeing such error: Uncaught ReferenceError: regeneratorRuntime is not defined Solution: in package.json, add: "browserslist":
阅读全文
摘要:We want to only freeze the private variable when we get it and set it: class Cart { #items; constructor(items = []) { this.value = items; } set value(
阅读全文
摘要:Morden Javascript allows us to write private and static class memebers. To do this, we need to install babel plugins: First, let see "static member":
阅读全文
摘要:Let's see two code snippets which has same functionalities: No1: function Cart(items = []) { this.items = Object.freeze(items); this.add = item => { c
阅读全文
摘要:Install: npm i --save joi Example: const schema = Joi.object({ username: Joi.string() .alphanum() .min(3) .max(30) .required(), password: Joi.string()
阅读全文
摘要:const factorial = (n) => (n > 1 ? n * factorial(n - 1) : 1); const memoize = (fn) => { const cache = {}; return (...args) => { const key = JSON.string
阅读全文
摘要:In contrast to other built-ins, Arrays can be wrapped transparently: const p = new Proxy(new Array(), {}); p.push('a'); assert.equal(p.length, 1); p.l
阅读全文

浙公网安备 33010602011771号