Qubyte Codes

Test friendly mixins

#JavaScript #games

I've recently been attempting to code a clone of the classic game asteroids using canvas in the browser. Since this is me, I've been distracted by all sorts of programming detours

Promises and Node.js event emitters don't mix

#JavaScript

To many experienced Node developers, the title of this post will seem intuitively obvious. Nevertheless, it's useful to see what unexpected behaviour can occur when the two are used together. Here's an example

Progressive enhancement #1

#CSS #JavaScript

When I first put together the CSS for this blog I avoided a fixed header since the header felt a bit large, and I didn't want to take up too much space which could be used for content

Adding missing features to Set

#JavaScript

ES2015 bought a Set constructor to JavaScript. It's pretty barebones, consisting of a constructor which creates objects with a few methods for adding, removing, checking if something is a member, and iterating over the set. Instances have the essential quality of a set; an item is a member of the set or not a member. Unlike an array, an item cannot be an element more than once. In other words you can avoid using arrays and doing a lot of indexOf checking

A presentation on async-await and Toisu!

#JavaScript

Just before Christmas I gave a presentation on the upcoming async-await JavaScript language feature, its basis in promises and generators, and finally a tiny server framework (like Express but a lot leaner and more modular) which can make use of async functions as middleware (since an async function is indistinguishable from a normal function which returns a promise). I'll introduce Toisu! in a blog post soon, but until then here's the presentation

Interfaces for JavaScript

#JavaScript

I use instanceof a lot in JavaScript. It's very handy when writing unit tests. It's easier to do an instanceof check than it is to exhaustively probe an object

Private methods for JS classes

#JavaScript

This is a short companion to an earlier article I wrote on using WeakMap for private data with JS classes. While private data belongs to instances, private methods can be shared between instances of a class (just like its regular methods). An implementation using ES2015 modules looks like

Private data for JS classes with WeakMap

#JavaScript

Private data has always been awkward in JavaScript. It's particularly difficult when it comes to constructors, and with ES2015 recently published, classes too. Let's say we have an example class, exported by an ES2015 module