Search

Nalezeno "javascript": 270

Return a Default Value with Promises Using catch


Last week I tweeted all of you looking for your best JavaScript Array and Promise tricks, and as always, it didn’t disappoint — I learned quite a bit! Today’s JavaScript Promise trick is brought to you by Claudio Semeraro: how to use catch to set a default value instead of...

Break a forEach Loop with JavaScript


I’ve written a number of blog posts about JavaScript tricks: Promise tricks, type conversion tricks, spread tricks, and a host of other JavaScript tricks. I recently ran into another JavaScript trick that blew my mind: how to break a forEach loop. To break the forEach loop at any point,...

React.isValidElement


Knowing what input type you’ve received is hugely important in JavaScript, which is a big reason for Flow and TypeScript’s rise. One such case where it’s useful to know what an object represents is if the input is a string or a React element. To detect if an object is a React...

IMA.js – Testování aplikace


V minulých dílech jsme úspěšně vytvořili plně funkční IMA.js aplikaci na předpověď počasí. Abychom zajistili, že tato aplikace zůstane funkční i nadále a s dalšími úpravami nic nerozbijeme, doplníme ji o sadu jednoduchých, ale mocných testů

IMA.js – Testování aplikace


V minulých dílech jsme úspěšně vytvořili plně funkční IMA.js aplikaci na předpověď počasí. Abychom zajistili, že tato aplikace zůstane funkční i nadále a s dalšími úpravami nic nerozbijeme, doplníme ji o sadu jednoduchých, ale mocných testů

Lots of Ways to Use Math.random() in JavaScript


Math.random() is an API in JavaScript. It is a function that gives you a random number. The number returned will be between 0 (inclusive, as in, it’s possible for an actual 0 to be returned) and 1 (exclusive, as in, it’s not possible for an actual 1 to be returned). Math.random(); // returns...

Detect Generator Functions with JavaScript


In the current JavaScript climate of new syntaxes, features, and using loads of external libraries, it seems harder than ever to be sure what your functions are being given or even what the data represents. Of course, we’ve come up with Flow and TypeScript to help, but we can’t count...

Node isConnected


Every so often I discover a property in JavaScript objects that I didn’t know existed, oftentimes using another trick to accomplish the same functionality. One such property I just learned about was isConnected, a node property that attached to a context (i.e. document). Here’s how...

JavaScript Operator Lookup


Okay, this is extremely neat: Josh Comeau made this great site called Operator Lookup that explains how JavaScript operators work. There are some code examples to explain what they do as well, which is pretty handy. My favorite bit of UI design here are the tags at the bottom of the search...

Limit Promise Concurrency with pool


Methods like Promise.all, Promise.allSettled, Promise.race, and the rest are really excellent for managing multiple Promises, allowing for our apps to embrace async and performance. There are times, however, that limiting the number of concurrent operations may be useful, like rate limiting...

Smarter Ways to Generate a Deep Nested HTML Structure


Let’s say we want to have the following HTML structure: <div class='boo'<div class='boo'<div class='boo'<div class='boo'<div class='boo'</div</div</div</div</div That’s real a pain to write manually. And the reason why this post was born was being...

cookieStore: Async Cookie API


One pattern in the JavaScript API world that web development veterans will notice is that we’ve been creating new methods to accomplish what older, grosser APIs once achieved. XMLHttpRequest became the fetch API, some APIs like Battery became async, and there are dozens of other examples....

How to Prevent Pasting into an Input


Every once in a while I get to a website that doesn’t allow me to paste into a form input. In most cases it’s something to do with login credentials (username and or password) and auth codes. So how are they preventing me from pasting information? It’s as easy as you’d...

How to Conditionally Add Attributes to Objects


JavaScript is full of tricks that you don’t know you want until you … want … them. Or maybe just until you see them. One trick I recently realized was conditionally adding attributes to React elements. Of course this trick essentially boils down to conditionally adding properties...

Ryan stvořil Deno a bylo to dobré


S nadsázkou se dá prohlásit, že vzniku Deno vděčíme hryzavému svědomí Ryana Dahla, autora NodeJS. Za jedenáct let, které dělí první verzi NodeJS a první verzi Deno, se ve světě referenčního JavaScriptu událo mnohé. Následovník NodeJS je proto mnohými vítán

How to Detect When a Sticky Element Gets Pinned


The need for position: sticky was around for years before it was implemented natively, and I can boast that I implemented it with JavaScript and scroll events for ages. Eventually we got position: sticky, and it works well from a visual perspective, but I wondered how can we determine when...

The Flavors of Object-Oriented Programming (in JavaScript)


In my research, I've found there are four approaches to Object-Oriented Programming in JavaScript. Which methods should I use? Which one is "the best" way? Here I'll present my findings along with information that may help you decide which is right for you. The post The Flavors of Object-Oriented...

How to Create an Async Function


One thing I love about JavaScript is that there are many ways to accomplish the same task, one such example being creating functions. There are several patterns for functions; one of the last you see used is the new Function method: /* new Function(arg1, arg2 (...), body) */ const myFunction =...

IMA.js – Detailní pohled na komponenty, eventy a extensions


V předchozím díle jsme si na naší aplikaci s předpovědí počasí ukázali, jak vykreslit data pomocí Views a rozdělili jsme si HomeView do podrobnějších komponent. V tomto díle uděláme naši aplikaci pro uživatele zajímavější a přidáme možnost jak zadávat lokalitu

Nahoru
Tento web používá k poskytování služeb a analýze návštěvnosti soubory cookie. Používáním tohoto webu s tímto souhlasíte. Další informace