Looking back on 2012

2012 has been a very productive JavaScript year for me:


The problem with blogs

I’m a big fan of blogs. After all, I’m writing one, myself. They are the contemporary version of a specialized newspaper. Regularly having new content is exciting and reading blogs is well supported by various apps, thanks to standardized publication formats such as RSS and Atom.


Two ways of clearing an array in JavaScript

Update 2012-12-27: Better example for aliasing in Sect. 1.

In a blog post, David Walsh mentions two approaches for emptying (clearing) an array. This blog post explains the pros and cons of both approaches. In order to understand them, we first need to know about aliasing.


“Skyfall” plot holes

The latest James Bond movie, “Skyfall” was widely liked by critics and audiences. I left the movie a bit unsatisfied. There were also three plot holes that bothered me. All three have easy fixes.

[Warning: Spoilers ahead.]


Language complexity: C++, Ruby, CoffeeScript and JavaScript

Alex Corban has written an article on C++ Rocks that diagrams the complexity of three programming languages: C++, Ruby and CoffeeScript. Here is the bird’s eye view:


The future of JavaScript: a CoffeeScript-like workflow

ECMAScript 6 [1] will bring many new features to the language. However, it will be years before we can rely on it being supported in most browsers that are in use. This post examines tools that will allow us to program with ECMAScript 6 much sooner.


New Samuel: a font derived from Morse code

New Samuel is a font by Aurelian Hallhuber that he derived from Morse code (Samuel is one of Morse’s given names).


JavaScript puzzle: equal, but not the same

The following puzzle has been posted on Reddit by davvblack: What are the values of x and y, given the following interaction?
    > x === y
    > 1/x > 1/y


A few thoughts on iTunes 11

Apple recently released a new version of iTunes, iTunes 11. In the words of John Gruber (for Daring Fireball):
There are redesigns and there are redesigns. This one’s the real deal. It’s not a rewrite though. Clearly, in its heart, under the hood, this is still the same iTunes. It’s what you see [...] that’s all new.
It was time. The old design felt bloated and cluttered. Two general thoughts:


Using ES6 template strings for regular expressions

ECMAScript 6 template strings [1] give us multi-line raw (backslash has no special meaning) string literals and interpolation. But they can also be tagged, in which case a library can determine the meaning of their content. Steven Levithan has recently given an example of how they could be used for his regular expression library XRegExp.


I’m the new JavaScript Weekly editor

Update 2014-04-11: I stepped down as editor of JavaScript Weekly, I had a fun 15 months, but now need to focus on Ecmanauten, my company that provides all kinds of JavaScript training.

JavaScript Weekly (JSW) is a popular JavaScript email newsletter. It is reaching 35,000 subscribers and published by Cooper Press (along with several other developer-related newsletters). Peter Cooper, its creator and editor, has hinted at passing the torch to a mysterious new editor for a while. We can now finally reveal who it is: Starting with this Friday’s (Dec 7) issue, I’ll edit JSW. Peter will remain active in the background, doing quality control, suggesting links, etc. But most of the editorial work will be done by me.

A new way of delivering Retina images on the web

Recently, high-resolution screens (Apple calls them Retina displays) have become popular – first on cell phones, then on tablets and now on laptops. I have been waiting for those for literally decades: all other computer components (memory, processor speed, etc.) improved predictably, but screen resolutions did not get much better over the years. The problem for web developers is that things look nicely on these displays if resolution-independent mechanism are used: fonts, vector graphics, CSS effects, etc. However, with bitmap graphics, you are forced to deliver images with many more pixels. That has the potential of greatly slowing things down on the web if you are using a Retina device.

Daan Jobsis has found an interesting solution: Use a high-resolution JPEG image, but but with an extreme compression rate (e.g. 75%):


Arrays in JavaScript

Update 2012-12-17: New Sect. 3, “The Array constructor”.

This blog post goes deeply into how arrays work in JavaScript: they are much more like objects than you might think.


Next for iOS: better sharing

There is one important area where Android and Windows 8 are ahead of iOS: sharing data between applications [1]. Interestingly the foundations for improving things have already been laid. There are two parts when it comes to sharing: offering data and receiving data. The offering part already exists [2]: many apps have a “sharing” button. For example, things that can be done with the current page in Safari include: Create a bookmark, send the URL via email, tweet the URL.


Coercing objects to primitives

This blog post looks at how JavaScript coerces objects to primitives. If you don’t know the difference between primitive values and objects, I suggest you consult my article “Categorizing values in JavaScript” at the Adobe Developer Connection. This post was triggered by the following tweet by David Bruant:
!!(new Boolean(false)) #wtfjs
The result of the above expression is true. Let us first learn about coercion in JavaScript. We can then use that knowledge to understand this result.


Greg Smith on Goldman Sachs’s culture

Goldman Sachs executive Greg Smith resigned via an article in the New York Times, on March 14:
It might sound surprising to a skeptical public, but culture was always a vital part of Goldman Sachs’s success. It revolved around teamwork, integrity, a spirit of humility, and always doing right by our clients. [...] I am sad to say that I look around today and see virtually no trace of the culture that made me love working for this firm for many years.

[...] It makes me ill how callously people talk about ripping their clients off. Over the last 12 months I have seen five different managing directors refer to their own clients as “muppets,” sometimes over internal e-mail.


Jed – a JavaScript internationalization toolkit

Internationalization is still a tricky problem: we are still figuring out how to encode text properly, let alone store content in a manner that lets us translate it easily. In contrast, in other areas of web development, tools and technologies are in place so that even non-technical users can be productive. One example is content authoring – you don’t have to know how to write HTML or how to set up a server in order to publish a blog.


JavaScript inheritance: beyond the basics (video)

The video recording of my JSConf EU talk “JavaScript inheritance: beyond the basics” is online (you can also download the slides). Outline:
  • JavaScript inheritance basics
  • Object exemplars
  • ECMAScript 6 classes
  • Super-references
  • __proto__


A proposal for using Canvas in web workers

Ian Hickson, editor of the HTML spec, has proposed a way to let web workers use Canvas.


Nokia HERE (maps etc.): coming to iOS, Firefox OS and Android

Today, Nokia introduced a new brand for its location and mapping services: HERE. HERE applications will be available for several operating systems:

Variable declarations: three rules you can break

This blog post mentions three rules that are commonly given for using var statements. And then tells you when you can break them. To make things easier to understand, I somewhat disparagingly call the rules “conventional wisdom” and breaking the rules “unconventional wisdom”. But I will also explain why the rules have been created in the first place.


Four talks on ECMAScript 6/ECMAScript.next

Recently, there have been several good talks on ECMAScript 6: Additionally, you can take a look at the guide to my blog posts on ECMAScript.next.


A guide to 2ality’s posts on ECMAScript.next/ECMAScript 6

This blog post gives an overview of the 2ality posts on the next version of ECMAScript, ECMAScript 6 (code-named ECMAScript.next). All of those posts have the label esnext. Consult the sitemap for a list of all guides.


Daylight savings time

A few days ago, daylight savings time (DST) ended again in Germany (we call it Sommerzeit, literally “summer time”). Changing the time twice a year is a silly thing to do – it brings few savings and quite a bit of cost and inconvenience. The Pirate Party has now started a European initiative (page in German) for abolishing DST. The complicated thing in Europe is that all states have to participate, otherwise changing regulations does not make sense.

Dirk Haage pointed me to a nice visualization of daylight savings time. The visualization makes it obvious how we should change time – we should always have DST. I’d rather have slightly longer afternoons than early mornings. As a complementary measure, schools could start later. There is even evidence (page in German) that starting at 8 o’clock is too early for children (it certainly is for parents).


Property assignment and the prototype chain

This blog post examines how the prototype chain of an object affects assignments to its properties. It provides a more detailed look than the previous, more comprehensive, blog post “Properties in JavaScript: definition versus assignment”.


The text “__proto__” can break a webapp

[This post is part of a series on the special property __proto__]

The text “__proto__” can still break webapps if it appears somewhere in the content, as I was reminded of today, via Domenic Denicola and Peter van der Zee.


What is the best display aspect ratio for tablets?

One marked difference between current tablets is the aspect ratio of their displays. This blog post explores the pros and cons of the different aspect ratios, along with the question whether one of them is best overall.


Why aren’t there more women in tech?

We should never forget that programming was initially a female profession. It was only later that women were slowly driven out of the industry. I’ve always been surprised that there aren’t more women in tech. I suspect that it is partially an image problem – especially computer jobs are much better than their reputation. Case in point: at the university of Munich, many more girls study “Bioinformatics” or “Media Informatics” than plain ”Informatics”. (Valid) reasons I’ve heard were: seemed more interesting and contains less math. The interesting part is that, in my experience, students of Bioinformatics and Media Informatics are just as good at Informatics as Informatics students and often end up in “normal” computer jobs. Yet, prior to these degrees, these girls might not have studied anything computer-related.


Online conferences

Intriguing concept: the JavaScript Summit 2012 (Nov 13-15) is an online conference.


Object properties in JavaScript

Update 2013-08-25: Blog post “Protecting objects in JavaScript” (Object.preventExtensions(), Object.seal(), Object.freeze()).

Properties determine the state of an object in JavaScript. This blog post examines in detail how they work.


The future of Markdown

The basic idea of Markdown is simple: To create a document, one writes plain text (bullet lists are lines that start with dashes, styles are written **bold** and *italics*, etc.). To display a document, the plain text is converted to HTML. That gives you the best of both worlds: the plain text is to write (much easier than HTML), store and transfer; the rendered HTML is nice to look at. It is amazing how popular Markdown has become: GitHub supports it for files such as readmes and gists; Stack Overflow uses it for comments; Lean Publishing supports no other format for submitting books; many blog engines let you write posts in it; etc.


Summary of the October 2012 Apple event

This blog post summarizes what Apple has introduced yesterday.


Should Windows 8 be split into two operating systems?

Microsoft’s Windows 8 has a confusing split Metro/Desktop personality [1]. To make matters even more complicated, there is an additional version of Windows called Windows RT. This blog post argues that instead, Microsoft should have created two operating systems: one for tablets and one for desktops.


ECMAScript.next: TC39’s September 2012 meeting

Thanks to Rick Waldron, we have a detailed account of the decisions regarding ECMAScript.next that were made by TC39 [1] during its meeting from September 18-20, 2012. This blog post summarizes and explains the highlights.


Firefly – the animated series?

At New York Comic-Con, there was a panel for Joss Whedon’s space western Firefly. The show was canceled on TV in 2003 and followed up by a movie in 2005. Actor Nathan Fillion was asked the usual “Will there be more Firefly?” question. He answered: “If we’re dreaming, tell me what you think about this: ‘Firefly – the animated series’.” After the panel, Sean Maher provided more information. Quoting ”‘Firefly’ cartoon in the works?“ (by Kate Storey for the New York Post):

Sponsored blog posts: 50% off

To celebrate the arrival of fall and the increased traffic at 2ality, sponsored blog posts are 50% off, for one week.

Sponsored blog posts help me offset some of the costs of maintaining 2ality and ensure its long-term viability. You can use them to let 2ality’s readers know about web-related products, services, job offers, etc. Contact me, if you are interested. Details are explained here.


The myth of self-created millionaires

Quoting “Mitt Romney and the myth of self-created millionaires” by George Monbiot for The Guardian:
We could call it Romnesia: the ability of the very rich to forget the context in which they made their money. To forget their education, inheritance, family networks, contacts and introductions. To forget the workers whose labour enriched them. To forget the infrastructure and security, the educated workforce, the contracts, subsidies and bailouts the government provided.
It comes down to the question “How much more than normal employees should executives and company owners make?” And these are interesting points to consider.


JavaScript: parallel programming via River Trail coming to Firefox

2013-12-23: A new blog post on ParallelJS (as River Trail is now called) supersedes this post.

River Trail is a set of mechanisms that enable a new functional style of parallel programming in JavaScript. An initial prototype was developed by Intel. Recently, work has started to bring it to Firefox.


Invented swear-words and exclamations

Some swear-words and exclamations made up on TV and in the movies are really good. Favorites of mine:


Controlling the Mac user interface from the shell

The Mac OS X shell has several Mac-only commands for communicating with the graphical user interface (GUI). They are useful in three cases: First, when switching back and forth between shell and GUI. Second, when interacting with the system from a language that is not Objective C or AppleScript: Bash, Node.js [1], Python etc.


How to pronounce __proto__

[This post is part of a series on the special property __proto__]

Bracketing variable names with double underscores is a tradition in Python that JavaScript has borrowed a few times, most prominently for the property __proto__ [1] (which is currently non-standard, but will become part of ECMAScript 6). For Python, the following pronounciation has been suggested by Ned Batchelder:


JavaScript: __proto__

[This post is part of a series on the special property __proto__]

This blog post looks at the special property __proto__, which allows you to get and set the prototype of an object. In order to understand this post, you should be familiar with JavaScript’s prototypal inheritance [1].


The Yandex web browser

Yandex is the biggest search engine in Russia, with a 60% market share in that country. World-wide it ranks fifth. Yandex has just announced a new web browser:


Support for the Web Audio API is growing

Previously, there were two competing APIs for computing audio on the web [1]: (Desktop) Chrome had the Web Audio API, Firefox had the Audio Data API. The former has won this competition and support for it is growing:
  • Firefox: the Audio Data API is now deprecated on Firefox and the Web Audio API will be supported soon. Quoting “Web Audio In Firefox” by Robert O’Callahan:
    We don't have a specific date set for Web Audio support, but it is a high priority.

    At some point we will revisit MediaStreams Processing to get the features that Web Audio is missing, e.g., seamless stitching together of an audio and video playlist from a series of clips. That is lower priority.

  • Safari 6: supported, including iOS 6.
The API is still not supported on Android and Internet Explorer, though. It’s good to see that we are moving towards a common API in this domain. Getting cross-browser audio right was a major challenge for the HTML5 version of Angry Birds [2]. If you want to find out more about the Web Audio API, you can watch the video “Turning the Web Up to 11” (by Chris Wilson at Google I/O 2012) on YouTube:
This session will cover the web audio capabilities for games and music. We'll walk through the audio element and the Web Audio API, and dive deep into using the Web Audio API for game audio and building music applications. We'll also cover how to use the Node graph structure to build audio processing chains, and how to use analysis to do interesting tricks.


  1. Web audio APIs and the low-level approach
  2. Why the Angry Birds webapp needs Flash



The article “New Stanford/NYU study documents the civilian terror from Obama's drones” (by Glenn Greenwald for The Guardian) mentions interesting findings by a report on the use of drones by the US.
In the United States, the dominant narrative about the use of drones in Pakistan is of a surgically precise and effective tool that makes the US safer by enabling “targeted killing” of terrorists, with minimal downsides or collateral impacts.

This narrative is false.


Adobe’s new Create the Web products

During yesterday’s Create the Web keynote, Adobe announced several new products for web developers. This blog post gives a summary.


A quine in JavaScript

Quoting Wikipedia:
A quine is a computer program which takes no input and produces a copy of its own source code as its only output.
@cowboy (Ben Alman) gives the following example for JavaScript:
    !function $(){console.log('!'+$+'()')}()
Why does the quine work? The above code uses several tricks.


iOS 6 on the iPad

iOS 6 has become available today. The article “10 new iOS 6 features iPad users should know” summarizes what’s new for the iPad:


iPhone 5 and iOS 6 for web developers

The article “iPhone 5 and iOS 6 for HTML5 developers, a big step forward: web inspector, new APIs and more” (by Max Firtman for Breaking the Mobile Web) explains what’s new for web developers.


JavaScript: single quotes or double quotes?

Today, I’ve asked on Twitter:
JavaScript: single quotes versus double quotes. Any preferences?
And I got great answers. Two funny examples:


Thoughts on the September 2012 Apple event

Update 2012-09-14: There are three iPhone 5 models that support different bands (Sect. 7).

This post gives a few thoughts on the September 2012 Apple event.

Expressions versus statements in JavaScript

Update 2012-09-21: New in Sect. 4: using void for IIFEs, concatenating IIFEs.

This blog post looks at a syntactic distinction that is unfortunately quite important in JavaScript: the difference between expressions and statements.


How to get help for Linux: insult it

The Linux community does not take kindly to newbies. Thus, the trick is to insult Linux and you get all the help you need, because they want to prove you wrong. One user gives an example:


Twitter has become old media

Quoting “Twitter is old media” by O’Reilly’s Edd Dumbill:
[...] Twitter are switching off any kind of anonymous access to their API, restricting it to OAuth-identified server-to-server requests. Overnight, Twitter are no longer a platform. They're a media company with carefully monitored access agreements.
Similar to newspapers, cable TV companies, etc.

The empty regular expression

This blog post takes a look at the empty regular expression.


JavaScript: the glass is half full

JavaScript is widely used these days. But there are still many people who dislike it, which is why Dart and – to a lesser degree – CoffeeScript have passionate fans. Recently, Crockford, who has done much to establish JavaScript as a credible general-purpose programming language, called it “tragically important”. In this blog post, I argue that we should see JavaScript’s glass (cup?) as half full and not as half empty.


js-lang, a group for discussing JavaScript

I’ve created a new group called “js-lang” that focuses on JavaScript as a language. Quoting the description of js-lang:
This is a group about the JavaScript language proper. That is, specific platforms (browsers, Node.js, etc.) are excluded, but cross-platform initiatives and ECMAScript.next are included. Join to discuss related topics.
I’ll be there to answer questions and hope that others join to both ask and answer questions and to discuss various issues.


Gimp is now a native Mac app (no X11 needed)

The free image editing program Gimp has been available on Mac OS X for a while. But you always needed to install the X11 window environment to run it. That has changed: It can now be donwloaded as a native application. Tips:


The Zen of Python

The “Zen of Python” is a mini style guide for Python code that is also interesting if you don’t program Python. Its abstract reads:
Long time Pythoneer Tim Peters succinctly channels the BDFL's [Benevolent Dictator For Life, a nickname of Python creator Guido van Rossum] guiding principles for Python's design into 20 aphorisms, only 19 of which have been written down.


Firefox 15 tip: enable the built-in PDF viewer

Firefox 15 has been released. It comes with a built-in PDF viewer that is written in pure JavaScript (no plugins!) whose name is “pdf.js” [1].


What object is not an instance of Object?

Question: What object is not an instance of Object? Or, put differently: What value v makes the following three expressions true?
    typeof v === "object"
    v !== null
    !(v instanceof Object)


A guide to 2ality’s posts on the JavaScript language

This blog post gives an overview of the 2ality posts on language aspects of JavaScript. All of those posts have the label jslang. Consult the sitemap for a list of all guides.


A shirt that cools better than sweat

It is difficult to cool the body better than sweat (without involving a machine). Quoting “The First Shirt That Lowers Your Body Temperature” (by Berne Broudy for Popular Science):


Reload a web browser when a file changes (Node.js, Grunt, Mac)

2012-08-24: JSReload now also supports Chrome/Mac.

This blog post explains how to use Node.js to reload a tab in Safari whenever a file changes. Alas, this solution only works on a Mac, because it relies on AppleScript to remotely control Safari. You can download it as project JSReload on GitHub.


Chrome: click to play Flash

This blog post explains how to switch on “click to play” for Flash content in Chrome.


Distributed social networks, an alternative to Facebook and Twitter

Are you looking for an alternative to Facebook and Twitter? Do you think they should work more like email, with multiple servers, multiple apps, and the ability to move and back up your content? Then distributed social networks may interest you.


DOM: element IDs are global variables

Several tweets mentioned that in order to display an element in Chrome’s JavaScript console, you only have to type its ID. @johnjbarton pointed out that that is because all element IDs are global variables. This blog post explains a few more details.


A closer look at _.extend and copying properties

Underscore.js is a useful complement to JavaScript’s sparse standard library. This blog post takes a closer look at its extend function. Along the way, it will give a detailed explanation of how to best copy properties in JavaScript. This post requires basic knowledge of JavaScript inheritance and prototype chains (which you can brush up on at [1]), but should be mostly self-explanatory.


Get notifications of updated 2ality content via email

Let’s give this thing another try. While there was very little demand for a weekly email newsletter with 2ality’s content, I think a variant of it might make sense. If you follow this blog via a feed (RSS, Atom) then you don’t get notifications when existing content is changed (as you would via Twitter or Google+). That changes with the new “2ality updates” mailing list: expect 0-5 emails per month, notifying you of such occurrences. Subscribe here if you are interested.

Thank you for your attention,


Twitter’s future: cards

This blog post describes how Twitter sees its future: richer tweet content via “cards” and no more third-party clients.


Properties in JavaScript: definition versus assignment

Did you know that defining a property is not the same as assigning to it? This blog post explains the difference and its consequences. It has been triggered by an email from Allen Wirfs-Brock on the es-discuss mailing list.


Mars Science Laboratory – interesting links

“Curiosity” is the name of the Mars rover that landed successfully today. “Mars Science Laboratory” (MSL) is the mission name and describes what the rover is: A car-sized mobile lab. NASA launched the MSL spacecraft from Cape Canaveral, Florida, on Nov. 26, 2011. That is, it took Curiosity over 8 months to land on Mars. Here are a few links with more information on Curiosity:


ECMAScript.next: TC39’s July 2012 meeting

TC39 (Technical Committee 39) works on the upcoming ECMAScript.next [1] standard. They have several meetings per year and in July, there was another one. This blog post summarizes the most important decisions. It is based on the following minutes by Rick Waldron:


Newspapers: more money from subscribers, less from ads

The newspaper landscape has been changing for quite a while: Print subscriptions decline and while digital subscriptions increase, newspapers compete with free content on the web. One interesting recent development is that newspapers are increasingly funded by subscribers and less by ads.


Watching the Earth breathe

The Earth breathes: When vegetation grows, carbon dioxide is consumed and oxygen is produced. That is, carbon dioxide breathed in (obviously, we breathe oxygen in). That process is reversed when plants lose leaves and they decompose or are eaten by animals. The NASA Goddard Scientific Visualization Studio has created an animation that visualizes the breathing by showing both the cycle of vegetation and the concentration of carbon dioxide in the atmosphere:


ECMAScript 6: classes

[Update 2015-02-15] Newer version of this blog post: “Classes in ECMAScript 6 (final semantics)

During the July 2012 meeting of TC39 [1], classes have been accepted for ECMAScript 6, the upcoming version of the JavaScript language standard. This blog post explains how those classes work. It is based on Allen Wirfs-Brock’s annotated slides.


Why we wear pants and don’t wear hats

For a long time, pants were only worn in a few corners of the world. And as recently as 100 years ago, most men in the USA wore hats. This blog posts explains why those customs have changed.


Apply and arrays: three tricks

This blog post describes three tricks for working with arrays via apply.


Explaining to non-programmers what JavaScript is

When I tell non-programmers that what I do professionally involves JavaScript, I most commonly get the reaction: “Isn’t that that thing that you have to install and that makes the browser slow?”. This answer surprises me in two ways:


The third culture

The Third Culture is a movement that tries to bring two cultures together. Quoting “The Third Culture” by John Brockman:


Java’s Project Jigsaw (modularity): delayed

Project Jigsaw is about adding modularity to Java and about breaking up the currently monolithic runtime library. It was originally slated to be included in Java 8 (September 2013) and has now been postponed until Java 9 (September 2015).


Implementing a command line with eval in JavaScript

This blog post explores JavaScript’s eval function by implementing the foundation for an interactive command line. As a bonus, you’ll get to work with ECMAScript.next’s generators (which can already be tried out on current Firefox versions).

[Sponsor] Cospired: mobile and web development

Cospired is a new and passionate startup from Munich for your most challenging tasks. Founded by three software engineers with a strong background in mobile applications (iOS), web frontend (jQuery, Cappuccino) and backend development (Node.js, Rails, PHP), as well as network engineering. They like to translate your ideas into code and to help you find those ideas.

And now imagine what they can do for you...

Cospired sponsors this week on 2ality.


Programming: initially a female profession

In the 1940s, the first computer programmers were all women. That only changed later. Quoting “Researcher reveals how ‘Computer Geeks’ replaced ‘Computer Girls’” by Brenda D. Frink for the Clayman Institute for Gender Research:


Stan Lee: you’ve seen him in many movies

Stan Lee is one of the titans of comic book literature:
In collaboration with several artists, most notably Jack Kirby and Steve Ditko, he co-created Spider-Man, the Hulk, the X-Men, the Fantastic Four, Iron Man, Thor, and many other fictional characters, introducing complex, naturalistic characters and a thoroughly shared universe into superhero comic books.

Hence, even if you don’t read comic books, you’ve probably heard of his work. What you might not be aware of is that he has frequent cameos in movies:


Combining code editing with a command line

Update 2012-09-05: separated input and output.

Currently, you are forced to work with JavaScript code in either of two modes: You can either use a code editor and edit multiple lines or you can use an interactive command line and work with one line at a time (editing, evaluating). With jsrepl [GitHub project, live demo], I have prototyped a combination of both modes – no need to chose, any more.


Working with large integers in JavaScript

In JavaScript, one has at most 53 bits for integers. This blog post explains how to work with large integers, by encoding them in strings.


amdefine: use AMD modules on Node.js

James Burke’s npm module amdefine lets you write AMD modules [1] that also work on Node.js. To do so, you need to perform the following steps:


Text message lengths

Several text messaging technologies impose character limits on messages. This blog post describes those limits and their advantages.


Google I/O 2012, keynote day 2: the highlights

This blog post describes the highlights of the second-day keynote of the Google I/O conference [1]. Just like last year [2], it was more Chrome-themed, as opposed to the Android-themed keynote yesterday.


Google I/O 2012, keynote day 1: the highlights

Update 2012-06-29: Google I/O 2012, keynote day 2: the highlights

This blog post describes the highlights of the keynote of the first day of the Google I/O conference [1]. It does so from the vantage point of a developer and Apple user, so don’t be surprised to see developer information and comparisons with Apple.


Mozilla’s next-generation web browser Servo is making progress

Servo is Mozilla’s next-generation web browser [1], with a focus on parallelism and security. It’s not much more than a technology demo and will remain so for a while, but it’s making progress nonetheless. Quoting Patrick Walton in a thread on Google Groups:


The iPhone 5 to support NFC?

It will happen eventually, but rumors are increasing that the next iPhone will support Near Field Communication (NFC). NFC would enable the following features:


Do we need a crisis to change?

French researcher Emmanuel Todd has interesting ideas on what might happen if the Euro collapses. The following are quotes from the article “What Will Happen if the Euro Collapses? A Few Scenarios” (by Bruce Crumley for TIME.com), along with comments of mine.


Asynchronous programming and continuation-passing style in JavaScript

In this blog post, we give a name to JavaScript’s callback-based asynchronous programming style: continuation-passing style (CPS). We explain how CPS works and give tips for using it.


Windows Phone Summit: the highlights

This blog post summarizes what Microsoft announced at the Windows Phone Summit.


Microsoft’s new tablets: overview and thoughts

Update 2012-06-20: More information on pen input, new section “More information on the web”.

Yesterday, Microsoft introduced two new “Surface” tablets: One ARM-based version and one Intel-based version. This blog post summarizes the introductions and mentions a few thoughts of mine.


GIMP 2.8.0 on Mac OS X

GIMP 2.8.0 has come out and Simone Karin has created packages for Mac OS X.


Reading RSS and Atom feeds on the iPad

For a long time, I have been very happy with Google Reader for RSS/Atom feed reading. But it has been in slow decline. For example, it is slightly buggy on Firefox and almost unusable on the iPad. This blog post describes alternatives for the iPad.


JavaScript: sparse arrays vs. dense arrays

In general, arrays in JavaScript are sparse – they can have holes in them, because an array is simply a map from indices to values. This blog post explains how to create dense arrays, arrays without holes.


Apple’s WWDC announcements: a summary

Update 2012-06-13: New section “More material on the web”.

This blog post summarizes what Apple has introduced at the World-Wide Developer Conference in San Francisco, yesterday.


ECMAScript.next: for-of, iterators, generators

[2015-02-26] New version of this blog post: “Iterables and iterators in ECMAScript 6

ECMAScript.next’s for-of loop will provide a new and quirk-free way of iterating over all kinds of data. This blog post explains how it works and how you can try out a prototype implementation in Firefox 13 and later.


A wish list for iOS 6

Apple has been steadily improving iOS. With iOS 5, I especially liked how it made devices more independent of PCs. However, iOS still slows me down considerably compared to desktop operating systems with a real keyboard. This blog post contains a few ideas for fixing that.


A closer look at Underscore templates

Underscore.js is a highly useful complement to JavaScript’s rather sparse standard library. In a pinch, Underscore gives you simple templating, too. This post explains how it works and gives tips.


Notes from the Fluent JavaScript conference

Technical publisher O’Reilly organized their first JavaScript conference, called “Fluent”, May 29-31 in San Francisco. This blog post collects random impressions of mine from that conference. They should be interesting even if you haven’t attended Fluent (hint: links to videos).


Vacation: May

Dear 2ality readers, I’ll take May 2012 off from blogging, to have more time for various projects. On Thursday, May 31, I’ll hold a keynote and a talk at the Fluent Conference in San Francisco. If you are there, let me know so that we can meet up.

Hope to see you back here in June,


Prosperity without growth

Tim Jackson is Professor of Sustainable Development at the University of Surrey and author of the book “Prosperity without Growth: Economics for a Finite Planet”. In 2010, he held a talk on the topic of that book. This blog post summarizes it.


Google Drive – online storage

One day ago, Google presented Google Drive, online storage for files. This blog post summarizes what it is.


Declaring module exports (Node.js, AMD)

Modules are mostly the same in Node.js and AMD [1]: A sequence of statements that assign internal values to variables and exported values to an object. This blog post shows several patterns for doing the latter. It also explains how ECMAScript.next handles exports.


Four rules for living your life

Adrian Tan held the graduation speech “Life And How To Survive It” for the class of 2008 at Nanyang Technological University (in Singapore). In it, he states four rules for living one’s life:


How numbers are encoded in JavaScript

All numbers in JavaScript are floating point. This blog post explains how those floating point numbers are represented internally in 64 bit binary. Special consideration will be given to integers, so that, after reading this post, you will understand what happens in the following interaction:
    > 9007199254740992 + 1

    > 9007199254740992 + 2


Node.js: expanding shortened URLs

This blog post explains how one can use Node.js to expand a URL that has been shortened by a service such as t.co (built into Twitter) and bit.ly. We’ll look at a simple implementation and at an advanced implementation that uses promises.


Offer files for download in HTML5: a[download]

The new attribute download for <a> tags allows one to offer a file for download – instead of displaying it in the browser.


ECMAScript 6: arrow functions and method definitions

Follow-up blog post from 2013-08-11:Callable entities in ECMAScript 6”.

In JavaScript, one aspect of creating a function inside a method is difficult to get right: handling the special variable this. ECMAScript.next will make things easy by introducing two constructs: arrow functions and method definitions. This blog posts explains what they are and how they help.


Sturgeon’s Law

Sturgeon’s Law confirms my own suspicions:
Ninety percent of everything is crap.


Discrimination – four recent tech community controversies

Recently, four controversies have swept the tech online scene: They were about perceived discriminations against women, people who prefer not to drink, and homosexuals. This blog posts describes the controversies and mentions the most interesting commentaries on them. It concludes with thoughts on how we might learn from them.


Handing variables to eval

Problem: You have an object that assigns values to names and want to use those names in an expression that is to be evaluated by eval. The classic solution is to use the with statement. But that statement is deprecated [1], starting with ECMAScript 5 strict mode [2]. This blog post describes an alternative implementation technique.


Canada eliminates one-cent coins

Canada will eliminate its penny. The reason is cost: Each penny costs 1.6 cents to make. Quoting “Canada's penny withdrawal: All you need to know” on CBC News:

News via 2ality: March 2012

This monthly columns collects news on 2ality-related topics and links to posts where those topics were previously covered. It also lists blog posts that have been updated (so that you don’t have to follow on Twitter or Google+ to find out about them).


Converting a value to string in JavaScript

In JavaScript, there are three main ways in which any value can be converted to a string. This blog post explains each way, along with its advantages and disadvantages.


Arguments in favor or the “iPad mini”

A smaller version of the iPad has been rumored for quite some time. Recently, rumors have become more concrete: An “iPad mini” might come out before the end of the year, with a screen size of 7.85 inch. The article “Apple Has 163 Reasons To Release Fabled ‘iPad mini’” (by A.T. Faust III for AppAdvice) provides interesting arguments in favor of that theory. Highlights:


CSS Grid Layout is coming to Firefox in 2012

So far, HTML5 has been severely lacking when it comes to flexible GUI layouting. All that changed when Microsoft created CSS Grid Layout [1], which, among other things, is used to write the native HTML5 applications for Windows 8 [2]. That standard provides everything that people are familiar with from desktop GUI kits (such as Java SWT). Alas, so far, Microsoft was the only one who implemented this standard in a browser. Now that has changed: CSS Grid Layout will be added to Firefox in 2012 – as mentioned in section “CSS Flexbox and CSS Grid” of “Firefox in 2011 – Firefox plans for 2012” (by Robert Nyman for Mozilla Hacks).

In case you are wondering whether “CSS Grid” is the same as “CSS Grid Layout”, there are several similarly named specifications floating around, but they really are just different versions of the same standard:

  1. CSS Grid Positioning Module Level 3” (5 September 2007)
  2. Grid Layout” (22 March 2012)
  3. W3C Editor’s Draft: “CSS Grid Layout” (22 March 2012)
As an additional tidbit, the Firefox Platform 2012 Roadmap mentions that Work on CSS Grid Layout will start after CSS Flexbox, which is slated to be finished by Q2 2012.

Example layout:

  • auto: assign a size so that the content fits comfortably.
  • minmax(min-content, 1fr): the minimum size is min-content (the smallest size that still allows the content to be shown); the maximum size is “1fr”, a fraction value indicating to assign 100% of the additional space that remains after all maximum sizes have been reached.
Note: there are no absolute units such as pixels.
[Source of image: “CSS Grid Layout”]


  1. CSS3 Grid Layout is perfect for webapp GUIs
  2. A Windows 8 keynote review by a JavaScript programmer and Apple user


JavaScript’s two zeros

JavaScript has two zeros: −0 and +0. This post explains why that is and where it matters in practice.


Dallas Fed advocates breaking up large banks

The Federal Reserve Bank of Dallas (Dallas Fed) has issued its annual report. In it, it calls for a breakup of large banks. These are currently considered “too big to fail” (TBTF). The report argues that that is anti-capitalist.


Israelis and Iranians use Facebook to declare their solidarity

The article “Israeli-Iranian solidarity exchange sweeps Facebook” (by Dimi Reider for +972 Magazine) reports on a touching campaign on Facebook:


What are the most popular JavaScript keywords?

Ariya Hidayat has used his Esprima parser to count the most popular keywords in a corpus of JavaScript libraries.

Oracle discusses the features of Java 8, 9, and 10

Quoting “Java won't curl up and die like Cobol, insists Oracle” by Gavin Clarke for The Register:


7 foods experts won’t eat

Great article by Liz Vaccariello for Prevention: “The 7 foods experts won’t eat”. Those foods are:


Stricter equality in JavaScript

Update 2012-11-08: The is operator will not be added to ECMAScript (probably ever). But this article is still relevant, because Object.is() will be part of ECMAScript 6 and because it sheds light on how === works.

Most JavaScript programmers are aware that “normal” equality (==) should be avoided in favor of strict equality (===) [1]. However, every now and then you need something even stricter than ===: If you want to check for NaN or if you want to distinguish between -0 and +0. This blog post explains the details and ECMAScript.next’s [2] solution, the “is” operator.


SpeechJammer – a gun that makes it difficult to talk

You can impede someone’s speech by playing back to them what they are saying with a slight delay. SpeechJammer is a gun-like apparatus that uses this idea to prevent someone from speaking – at a distance.


Displaying numbers in JavaScript

This blog post explains how JavaScript displays numbers. It also examines when JavaScript uses exponential notation and when it uses fixed notation.


“Movie: The Movie” – a funny, star-studded fake trailer

In his after-Oscar special, Jimmy Kimmel presented a fake trailer for the fake film “Movie: The Movie”. (Or is it a real trailer for a fake film? The film clearly doesn’t exist, but the trailer does.) It’s funny and has lots of stars in it.


Apple’s 2012 iPad event: the highlights

Update 2011-03-09: More links under Sect. 2.

This post summarizes what Apple has introduced yesterday.


The jQuery Foundation has been created

jQuery has previously been managed by a board that was part of the Software Freedom Conservancy. Now an independent foundation has been created to perform that task.


Private data for objects in JavaScript

Update 2012-10-21: In September 2012, The term “private name object” has been changed to “private symbol”.

JavaScript does not come with dedicated means for managing private data for an object. This post describes five techniques for working around that limitation:


The month at 2ality: February 2012

To be notified of updates of existing content on 2ality, you have to follow @rauschma on Twitter. Not everyone is willing or able to do that. Therefore, this new monthly column collects that information and makes it available as a blog post. It also reports on current topics that were previously covered on 2ality.


Raspberry Pi – a credit-card sized Linux computer for $35

Update 2011-03-09:Raspberry Pi Linux distro released, but the $35 computer faces new delays” by Ryan Paul for Ars Technica.

Today the Raspberry Pi Foundation announced that one can now buy the Raspberry Pi, a credit-card sized computer board that costs only $35. The Foundation entered licensed manufacture partnerships with two British companies to produce and sell the device. One of the two, RS Components (RS) is already experiencing tremendous interest in the Raspberry Pi. Quoting Chris Page, General Manager, Electronics at RS:

Array.prototype.concat is not generic

The ECMAScript 5.1 specification states that the array method concat is generic [1]. This post argues that that isn’t true in practice.


New Node.js module “lazylines”: read a text stream, line by line

The new Node.js module “lazylines” allows you to read a text stream, one line at a time, lazily.


Generate emails via mailto URLs on Node.js

This post tells you how to generate emails on Node.js and open them in an email program. It uses mailto URLs to do so. The advantage of this approach is that you can manually check and edit such emails before sending them.

openurl – a Node.js module for opening URLs

openurl is a Node.js module for opening a URL via the operating system. This will usually trigger actions such as:
  • http URLs: open the default browser
  • mailto URLs: open the default email client
  • file URLs: open a window showing the directory (on OS X)


Gatekeeper: Apple is taking security seriously

OS X 10.8 Gatekeeper in Depth” by Rich Mogull (for Securosis Blog) is an excellent analysis of Mountain Lion’s [1] new security features. It also gives Microsoft its due, which is rare in Apple reporting. Quote:


Major and minor JavaScript pitfalls and ECMAScript 6

Update 2012-02-24: New content in sections
  • 2.1. Function-scoped variables
  • 2.2. Inadvertent sharing via a closure
  • 2.7. for...in is weird

JavaScript has many pitfalls. This post examines whether they make JavaScript “unfixable” as a language – as some argue. To do so, it separates the pitfalls into two categories: The ones that become harmless after learning about them and the ones that don’t. We’ll also look at how the upcoming ECMAScript 6 fixes most problems.

Warning: If you are new to JavaScript then don’t let this post be your introduction to it. Consult other material first.

iCal: disable page flip animation, stitched leather look

There are two ways to disable iCal’s agonizingly slow page flip animation:


Flash browser plugin on Linux to be Chrome-only

Quoting “Adobe and Google Partnering for Flash Player on Linux” by Mike Chambers for the Adobe AIR and Adobe Flash Player Team Blog:


Twitter to eliminate their hashbang (#!) URLs

In a conversation triggered by Tim Haines, Twitter front end engineer Dan Webb refers to his article “It's About The Hashbangs” on the problems of using #! URLs in JavaScript. He then goes on to confirm:


Integers and shift operators in JavaScript

JavaScript only has floating point numbers. This post explains how integer operations are handled, specifically the bit shift operations. It will also answer the question whether n >>> 0 is a good way of converting a number to a non-negative integer.


Transforming HTML with Node.js and jQuery

The npm module jsdom enables you to use jQuery to examine and transform HTML on Node.js. This post explains how.


OS X Mountain Lion

Update: Section “More information on the web”.

Apple has just introduced the next version of OS X, called “Mountain Lion”. It will be available in late summer. This post summarizes the highlights.


NaN and Infinity in JavaScript

Update: New section “Detecting NaN”.

This post looks at two special values that can be the result of operations that normally return numbers: NaN and Infinity.


Taming tabs and bookmarks

Tabs were a major usability advancement for web browsers. They make it much easier to work with multiple locations at the same time and the ability to open links “in the background” turns them into a to-do list for pages that one still wants to read. However, before long, tabs also exhibit the negative traits of to-do lists: There are too many things still to consider and everything grows stale. This post presents ideas for how to tame tabs, for how to avoid those traits. Some of the ideas can be put into practice right now, others are about improving browsers and making a mental shift to fully exploit those improvements.

Season guide: “Star Trek: Enterprise” S3

The first two seasons of Star Trek: Enterprise were disappointing. The arc of the Temporal Cold War simply failed to engage me emotionally. All that changed with season 3 that largely dispensed with that arc and turned in a nicely plotted serialized story. Even though it is almost 10 years old, it is still fun to watch and reminded me of how much I miss having space-borne sci-fi on TV.


Exemplar patterns in JavaScript

This post explores exemplars (factories for objects) and how to implement them. The term exemplar has been proposed by Allen Wirfs-Brock to avoid the term class, which is not a good fit for JavaScript: Exemplars are similar to classes, but they are not classes.


PDF.js: display PDF files in your browser, without native code

Update 2012-08-29: Firefox 15 tip: enable the built-in PDF viewer

Quite amazing: PDF.js is a JavaScript library that displays PDFs in browsers. At version 0.2, it comes with the requisite warning: “Note: This is an early-stage prototype. Several documents might not render properly.”


Servo: a vision for the future of Firefox

  • 2012-06-28: Restructured much of the content, to make it easier to digest.
  • 2012-06-27: New section “More information on Servo”.
Recently, Mozilla stopped the Electrolysis project [1] that was to give Firefox per-tab processes. Hence, I was relieved when David Bruant pointed out to me that Mozilla haven’t given up on a parallel browser. They are working on a project called Servo which is being implemented in the Rust programming language.


What is {} + {} in JavaScript?

Recently, the lightning talk “Wat” by Gary Bernhardt pointed out an interesting JavaScript quirk: You get unexpected results when you add objects and/or arrays. This post explains those results.

Trying out Underscore on Node.js

Underscore is a library that nicely rounds out JavaScript’s rather limited standard library. Thanks to the Node Package Manager, it’s very simple to install on Node.js:
    $ npm install underscore


The increasing pervasiveness of JavaScript – a few historic milestones

Update 2012-07-20: O’Reilly has published my mini-ebook “The Past, Present, and Future of JavaScript”. It is free, but you have to enter a name and an email in the box at the right. This ebook can be considered an updated and extended version of this blog post.

JavaScript is used in more and more places. It started out as a scripting language for web content and has migrated to many areas. This post presents the historic milestones of this process. Note: The milestones are about things that changed the public perception of what JavaScript could be used for. Some of these milestones would not have been possible without prior work by others. For example: Mozilla’s contributions in advancing the state of JavaScript cannot be overestimated. The following are the milestones, in chronological order:


Remedies for SOPA causes (a greedy industry in decline, corrupt politics)

This post examines two reasons for why a bill such as SOPA [1] could come into being: First, Hollywood is a greedy industry in decline. Second, it wields significant power via corrupt politics.


JavaScript myth: JavaScript needs a standard bytecode

The idea is obvious: Why not standardize the bytecode of the virtual machines (VMs) that JavaScript runs on? That would mean that JavaScript programs could be delivered as bytecode and thus would be smaller and start more quickly (after having been loaded). Additionally, it would seem to be easier to port other languages to web browsers, by targeting that bytecode. This post makes its case in two steps: First, it shows that bytecode has several disadvantages. Second, it explains that source code is not as bad a solution as it seems.


Apple and the online education revolution

Yesterday’s Apple event on education reflects current trends in computerized learning. So what has Apple introduced?

What is JavaScript’s typeof operator used for?

JavaScript’s typeof is a complicated beast – it can be used for many things, but also has many quirks. This post lists its use cases, points out problems and presents alternatives.


The “no asshole comments” option

This post contains a few thoughts on what can be done about negative comments.


VLC keyboard shortcuts

Tip: “Preferences... → Hotkeys” lists VLC shortcuts. Two handy ones:


The first ECMAScript.next features in Firefox and Chrome

Update 2012-01-23:ECMAScript 6 support in Mozilla” on the Mozilla Development Network.

The next version of ECMAScript (code-named ECMAScript.next [1]) will be standardized by 2013. This post enumerates the first features that are currently being tested in Firefox and Chrome.


Samsung to merge its Bada and Tizen mobile operating systems – Intel still on board?

Quoting “Samsung Merging Its Bada OS With Intel-Backed Tizen Project” by Elizabeth Woyke for Forbes [via Ariya Hidayat]:

Streaming a DVD to another Mac via VLC

This post shows you how to stream a DVD from a sending Mac (e.g. an iMac) to a receiving Mac (e.g. a MacBook Air) using the free VLC media player. The explanation is also valid for other systems running VLC, but you will have to substitute a VNC server and client for the Mac’s built-in Screen Sharing (which is, in fact, based on VNC).


Automatically numbering headings via CSS

This post shows you how to number HTML headings with CSS. That is, given the following HTML.
    <h1>My Article</h1>
With the proper CSS, the above will be displayed as
My Article
1. Introduction
1.1. Rationale
2. Background


GitHub: serve files to the web, with a single branch

GitHub has a nifty feature called GitHub Pages that allows you to serve files in your repository to the web. Those files have to reside in the branch gh-pages, which is different from the usual master branch. To avoid the slightly cumbersome maintenance of two branches, this post shows you how to only work with gh-pages.


JavaScript inheritance by example

Update 2012-03-19: New section on “Objects”, tips for what to read next.

This blog post illustrates several JavaScript inheritance topics via an example: We start with naive implementations of a constructor Point and its sub-constructor ColorPoint and then improve them, step by step.


Crockford’s JSDev: switching off privacy for testing

Today, Douglas Crockford introduced a new project: JSDev. It solves a challenge with privacy: On one hand, you don’t want the outside world to have access to private functionality. On the other hand, you want to test it, via external unit tests.


The pitfalls of using objects as maps in JavaScript

JavaScript is Spartan when it comes to built-in data structures. One commonly uses objects as maps from strings to values. This post points out three pitfalls when doing so.

Dion Almaer on the history of webOS

Dion Almaer was head of webOS developer relations at Palm. He gives a nice account of the history of webOS. Quote:


The multiple roles of JavaScript objects and arrays

Both objects and arrays play multiple roles in JavaScript. This blog post explains what those roles are.