background preloader

JavaScript

Facebook Twitter

Matt Gaunt - Fetch is the new XHR. Fetch(), defined in the Fetch API, is a new API which allows you to make requests similar to XHR's, but has a simpler / friendly API.

Matt Gaunt - Fetch is the new XHR

The Fetch API is available in service workers today and in the global space (a.k.a in the normal Chrome window) if you enable the Experimental Web Platform Features in After getting asked about how to make an XHR for push notifications from service worker, I realised I had never attempted to view the contents of a fetch request, so did a little mucking around and put together a few examples (largely for my own peace of mind). Request a url, get a response, happy days. We start by checking the response status is 200 before examining the text of the response (assuming the response is text). Because the response of a fetch request is a stream, the text() method consumes the stream, hence the promise. If you run this from any page that isn't on the origin ' then an error will be thrown, "Failed to fetch".

What does "TypeError" mean? Cough Orig. 7 tips for a Node.js padawan. Learning JavaScript Design Patterns. Design patterns are reusable solutions to commonly occurring problems in software design. They are both exciting and a fascinating topic to explore in any programming language. One reason for this is that they help us build upon the combined experience of many developers that came before us and ensure we structure our code in an optimized way, meeting the needs of problems we're attempting to solve.

Read JavaScript Allongé. A Pull of the Lever: Prefaces “Café Allongé, also called Espresso Lungo, is a drink midway between an Espresso and Americano in strength.

Read JavaScript Allongé

There are two different ways to make it. The first, and the one I prefer, is to add a small amount of hot water to a double or quadruple Espresso Ristretto. Like adding a splash of water to whiskey, the small dilution releases more of the complex flavours in the mouth. “The second way is to pull an extra long double shot of Espresso. Enter the World of Node.js. Everyone talks about Node.js these days, but you’re not quite sure what it is?

Enter the World of Node.js

Or, do you just want to impress your friends with some nerd knowledge? This article will take you on a quick ride through the world of Node.js! Background On May 27, 2009 Ryan Dahl released the initial version of an open-source software platform written in JavaScript and C++. But why did he name it Node? Koa - next generation web framework for node.js. JavaScript Best Practices. Introduction The use of JavaScript has exploded over time.

JavaScript Best Practices

Now it is practically unheard of for a website not to utilize JavaScript to some extent. As a web developer who has concentrated on back-end coding in C# and front-end look and feel via HTML and CSS, my skills in JavaScript evolved over time instead of by conscious effort. While this is not uncommon, it can allow for some bad habits to be formed. 10 bonnes pratiques JavaScript. Au fil des formations, je remarque que de nombreuses bonnes pratiques que je signale en passant dans le code, par acquis de conscience, ne sont pas connues, ou pas comprises, ou juste surprenantes pour les stagiaires.

10 bonnes pratiques JavaScript

C’est l’occasion de me souvenir que dans tous les domaines, ce qui peut paraître évident et « connu de tous » ne l’est pas forcément, et qu’il est toujours bon de remettre en lumière des savoirs dont on imagine, souvent à tort, qu’ils sont monnaie courante. Voici donc dix bonnes pratiques choisies parmi un large ensemble de candidates ; vous en connaîtrez sûrement certaines, mais probablement pas toutes. Je pensais qu’il en faudrait 10 pour faire un article un peu consistant, et au final c’est un mammouth qui aurait pu être découpé en plusieurs articles histoire de faire durer le plaisir… Mais je suis d’humeur généreuse et j’ai encore plein d’articles sous le coude, alors je vous livre tout ça d’un coup :-) Adequately Good - JavaScript Module Pattern: In-Depth - by Ben Cherry.

The module pattern is a common JavaScript coding pattern.

Adequately Good - JavaScript Module Pattern: In-Depth - by Ben Cherry

It's generally well understood, but there are a number of advanced uses that have not gotten a lot of attention. In this article, I'll review the basics and cover some truly remarkable advanced topics, including one which I think is original. The Basics We'll start out with a simple overview of the module pattern, which has been well-known since Eric Miraglia (of YUI) first blogged about it three years ago. If you're already familiar with the module pattern, feel free to skip ahead to "Advanced Patterns". Anonymous Closures This is the fundamental construct that makes it all possible, and really is the single . (function () { // ... all vars and functions are in this scope only // still maintains access to all globals }()); Notice the () around the anonymous function.

Global Import JavaScript has a feature known as . Luckily, our anonymous function provides an easy alternative.