随笔分类 -  Javascript

上一页 1 ··· 5 6 7 8 9 10 11 12 13 ··· 31 下一页
摘要: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 阅读(50) 评论(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 阅读(61) 评论(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 阅读(79) 评论(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 阅读(49) 评论(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 阅读(80) 评论(0) 推荐(0)
摘要: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 阅读全文
posted @ 2021-11-05 15:36 Zhentiw 阅读(52) 评论(0) 推荐(0)
摘要: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, 阅读全文
posted @ 2021-11-03 01:05 Zhentiw 阅读(34) 评论(0) 推荐(0)
摘要:The Event Delegation Pattern Event delegation is a simple, but powerful leveraging of the DOM event system which allows for easier adding of functiona 阅读全文
posted @ 2021-08-19 15:40 Zhentiw 阅读(757) 评论(0) 推荐(0)
摘要: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({} 阅读全文
posted @ 2021-08-19 15:20 Zhentiw 阅读(58) 评论(0) 推荐(0)
摘要:removeEventListener removes an event listener added with addEventListener. However, there are a number of gotchas to watch out for in order to correct 阅读全文
posted @ 2021-06-14 15:01 Zhentiw 阅读(90) 评论(0) 推荐(0)
摘要:const items = [ 'Sojourner', 'Opportunity', 'Spirit', 'Curiosity', 'Perseverance', ] const formatter = new Intl.ListFormat('en', { style: 'long', type 阅读全文
posted @ 2021-02-21 21:49 Zhentiw 阅读(153) 评论(0) 推荐(0)
摘要: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 阅读全文
posted @ 2021-02-03 15:48 Zhentiw 阅读(90) 评论(0) 推荐(0)
摘要:let getUrl = url => listener => { let controller = new AbortController() let signal = controller.signal fetch(url, {signal}) .then((response) => { ret 阅读全文
posted @ 2020-11-26 03:09 Zhentiw 阅读(159) 评论(0) 推荐(0)
摘要:While using async/await, seeing such error: Uncaught ReferenceError: regeneratorRuntime is not defined Solution: in package.json, add: "browserslist": 阅读全文
posted @ 2020-11-26 03:00 Zhentiw 阅读(154) 评论(0) 推荐(0)
摘要: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( 阅读全文
posted @ 2020-11-05 20:04 Zhentiw 阅读(83) 评论(0) 推荐(0)
摘要: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": 阅读全文
posted @ 2020-11-05 19:57 Zhentiw 阅读(153) 评论(0) 推荐(0)
摘要:Let's see two code snippets which has same functionalities: No1: function Cart(items = []) { this.items = Object.freeze(items); this.add = item => { c 阅读全文
posted @ 2020-11-05 18:19 Zhentiw 阅读(83) 评论(0) 推荐(0)
摘要:Install: npm i --save joi Example: const schema = Joi.object({ username: Joi.string() .alphanum() .min(3) .max(30) .required(), password: Joi.string() 阅读全文
posted @ 2020-09-13 22:09 Zhentiw 阅读(212) 评论(0) 推荐(0)
摘要:const factorial = (n) => (n > 1 ? n * factorial(n - 1) : 1); const memoize = (fn) => { const cache = {}; return (...args) => { const key = JSON.string 阅读全文
posted @ 2020-09-06 17:23 Zhentiw 阅读(134) 评论(0) 推荐(0)
摘要: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 阅读全文
posted @ 2020-08-27 02:52 Zhentiw 阅读(164) 评论(0) 推荐(0)

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