2011-06

Prototypes as classes – an introduction to JavaScript inheritance

[2011-06-25] esnext, dev, javascript, jslang
Updates – read first: JavaScript’s prototypal inheritance is hard to understand, especially for people coming from other languages that are used to classes. This post explains that it does not have to be that way: The proposal “prototypes as classes” is a simplification of classes and inheritance in JavaScript. It might become part of ECMAScript.next, a.k.a. “the next version of JavaScript” (after ECMAScript 5). But there is also a library that allows you to use its features in today’s JavaScript. What’s intriguing about prototypes as classes is that they aren’t a radical departure from current practices, but rather a clarification of them.

Incidentally, this post is also a good introduction to JavaScript inheritance, because the basics are easier to understand with prototypes as classes.

Translating CoffeeScript classes to JavaScript

[2011-06-23] dev, javascript, coffeescript, jslang
The post “Classes in Coffeescript” contains an interesting juxtaposition of CoffeeScript code and the JavaScript it is translated to. This post examines the result of the translation in more detail, which nicely illustrates how subclassing works in JavaScript. To understand the following, you should be familiar with JavaScript’s prototypal inheritance (explained here).

What’s up with the “constructor” property in JavaScript?

[2011-06-22] dev, javascript, jslang
All objects produced by built-in constructor functions in JavaScript have a property called constructor. This post explains what that property is all about.

Quick JavaScript tip: trailing commas inside an object literal

[2011-06-20] dev, javascript, jslang
It used to be that some JavaScript engines weren’t picky about trailing commas inside an object literals, while others threw a syntax error. The ECMAScript 5 language specification [1] has made trailing commas legal, via the following syntax rule (in Sect. 11.1.5):

ECMAScript.next: the “TXJS” update by Eich

[2011-06-17] esnext, dev, javascript
Updates: Brendan Eich held a talk [1] at the TXJS conference in which he detailed the latest updates on ECMAScript.next. This post lists the highlights of his slides and adds a few explanations.

Erich Gamma (Eclipse) joins Microsoft to work on JavaScript tools

[2011-06-15] dev, javascript, windows 8, microsoft
If you have ever read the “Gang of Four” book on design patterns [1] or worked with the Eclipse Java IDE (and platform) then you are probably familiar with the name Erich Gamma who was deeply involved in both. Recent news was that Gamma had left IBM and stopped working on Eclipse [4]. Now Microsoft announces that he will join them [source: Heise via Ludwig Adam]. Quote:

Equality in JavaScript

[2011-06-15] dev, javascript, jslang
Update 2011-12-02: When is it OK to use == in JavaScript?

There are two operators for comparing values in JavaScript: strict equality === and “normal” (or lenient) equality ==. Many style guides (correctly) tell programmers to avoid lenient equality and always use strict equality. This post explains why.

Tip: use JavaScript as a calculator in Firefox and Chrome

[2011-06-10] browser, firefox, hack, javascript, computers, clientjs, chrome
The following tip allows you to quickly perform calculations via JavaScript in Firefox and Chrome. Many people use Google for this purpose, but this tip even works if your computer is offline.

Implementing bookmarklets in JavaScript

[2011-06-08] bookmarklet, dev, javascript, clientjs
Bookmarklets are little plugins for your browsers: JavaScript programs packed into javascript: URLs that you add to your bookmarks and start by clicking on them. They perform an operation on the currently open web page such as submitting it to Twitter. There are even bookmarklets that transform the current web page, for example, to add icons that, when clicked, add an event to Google Calendar. A separate post explains what bookmarklets are in more detail. This post tells you how to implement bookmarklets. It presents techniques, tools, and patterns for doing so.

JavaScript’s with statement and why it’s deprecated

[2011-06-01] dev, javascript, jslang
This post explains how the with statement works in JavaScript and why its use is discouraged.