[2011-11-04] “Myth: JavaScript needs classes” introduces a more concise name for “prototypes as classes”: object exemplars. An exemplar is a factory for instances, constructors are function exemplars.
[2012-10-03] Since this article has been written, it was decided that ECMAScript will have the special property __proto__ instead of the <| operator.
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.
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).
All objects produced by built-in constructor functions in JavaScript have a property called constructor. This post explains what that property is all about.
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):
2011-09-25: More and updated material on proxies, array comprehensions, and classes. Moved private name objects to new post.
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.
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:
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.
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.
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.