随笔分类 -  Javascript

上一页 1 ··· 5 6 7 8 9 10 11 12 13 ··· 30 下一页
摘要: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 阅读(50) 评论(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 阅读(31) 评论(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 阅读(740) 评论(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 阅读(54) 评论(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 阅读(83) 评论(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 阅读(150) 评论(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 阅读(83) 评论(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 阅读(156) 评论(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 阅读(151) 评论(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 阅读(80) 评论(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 阅读(82) 评论(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 阅读(211) 评论(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 阅读(131) 评论(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 阅读(163) 评论(0) 推荐(0)
摘要:Instances of most built-in constructors also use a mechanism that is not intercepted by Proxies. They therefore can’t be wrapped transparently, either 阅读全文
posted @ 2020-08-27 02:50 Zhentiw 阅读(145) 评论(0) 推荐(0)
摘要:For a Proxy, function signature looks like: const target = {} const handler = { get(target, propKey) { return Reflect.get(target, propKey) } } const p 阅读全文
posted @ 2020-08-27 02:46 Zhentiw 阅读(138) 评论(0) 推荐(0)
摘要:_.omitBy and its sibling _.pickBy are popular utilities which apply filter-like functionality to objects. Both of them accept a function to determine 阅读全文
posted @ 2020-08-18 01:54 Zhentiw 阅读(276) 评论(0) 推荐(0)
摘要:Remove duplicates elements from an array is a common array task Javascript offers different alternatives to accomplish it. You can use a mix of method 阅读全文
posted @ 2020-08-12 02:34 Zhentiw 阅读(170) 评论(0) 推荐(0)
摘要:When needing to format a number I've tended to lean towards Number.prototype.toFixed(), reach for a 3rd party library, or write custom functions. Howe 阅读全文
posted @ 2020-08-10 15:57 Zhentiw 阅读(283) 评论(0) 推荐(0)

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