Using ES6 Destructuring to assign class properties

Destructuring assignment (MDN Reference) is one of the best new JS features (especially coupled with default arguments and the spread or rest operator). If you aren’t familiar with destructuring assignment, there are lots of great examples in the link above, but here are a few: Arrays: const numbers = [1, 2, 3]; const [a, b, …

Getting Started with ES6 Classes

Though ES6 hasn’t been completely adopted anywhere quite yet (keep up on that), you can take advantage of many of its features today using libraries like Traceur and the ES6 module loader polyfill or using iojs with various –harmony flags (David Walsh has a nice writeup on all the harmony feature flags in io.js). In this post I …

Simple Javascript Table Filtering

Let’s say you have a smallish table that you want to allow your users to filter (via text search), but don’t necessarily want to install another plugin. I recently found myself in this position and decided it would just be easier to make my own simple filter. The requirements were simple: Filter will be a …

String Searching in Javascript

New Javascript developers frequently ask how to search for a string within another string using Javascript. The indexOf method is what you are looking for and is available on String and Array objects. String.indexOf(searchValue) returns the index of (hence the name) the first match OR -1 if the value was not found, it does not …

jQuery Transactions using Promises

I’ve had a couple projects recently where I needed to perform an action pending the successful completion of a variable number of AJAX requests. In the past, I have used a global counter to keep track of the number of successful requests, in the fashion of: This sort of works, but running the counter check …

Fluent Conference 2013 Links

Here are this most interesting links I took away from the 2013 O’Reilly Fluent Conference, please comment if you have more to share: Online O’Reilly book authoring and consumption: Atlas Beta – The new learning environment from O’Reilly Interesting Global Hackathon with good prizes: Battle Hack – 10 cities + 1 world final == $100,000 …

Firing asynchronous quantcast pixels

If you are building an AJAX-driven web application (like a swipe-driven mobile website) and want to register quantcast pageviews at times other than window.onload, here is a small change to the code snippet quantcast provides that will get you there. Note that this does not remove or replace any existing functionality, you will still need …

Being a Better Javascript Developer

I have gone through numerous phases of javascript development, peer reviewed a metric ton of other people’s Javascript and have experimented quite a bit with the old and new Javascript APIs and have found some common things that make code “good”. My aim is to help you be a more thoughtful javascript developer (though the …

Check client language with Javascript

It is simple enough to detect the end-users preferred language: var language = window.navigator.userLanguage || window.navigator.language; This will be a country code, for example ‘it’ or ‘en-US’ Example This particular example uses the Google Translate service and will trigger the translate widget to show up if their language is different from your target language: [raw] …

understanding javascript closures

Closures, Lambda, Anonymous functions or whatever else you may call them have become commonplace in modern Javascript, thanks in large part to libraries like Prototype and jQuery. There are many ways to write closures and some common design patterns that utilize closures, I will do my best to explain the what and why. Required Knowledge …