Posts

Showing posts from December, 2014

Symbols in ECMAScript 6

Symbols are a new primitive type in ECMAScript 6 [1] . This blog post explains how they work. A new primitive type ECMAScript 6 introduces a new primitive type: symbols. They are tokens that serve as unique IDs. You create symbols via the factory function Symbol() (which is loosely similar to String returning strings if called as a function): let symbol1 = Symbol(); Symbol() has an optional string-valued parameter that lets you give the newly created symbol a description: > let symbol2 = Symbol('symbol2'); > String(symbol2) 'Symbol(symbol2)' Every symbol returned by Symbol() is unique, every symbol has its own identity: > symbol1 === symbol2 false You can see that symbols are primitive if you apply the typeof operator to one of them – it will return a new symbol-specific result: > typeof symbol1 'symbol' Aside: Two quick ideas of mine. If a symbol has no description, JavaScript engines could use the name of the v...

On Censorship

Image
It was a surreal experience this week reading Una M. Cadegan’s thoroughly researched academic text, All Good Books Are Catholic Books:  Print Culture, Censorship, and Modernity in Twentieth-Century America (Cornell University Press, 2013) while watching North Korea enact its own censorship of The Interview (Columbia Pictures, 2014), forcing Sony Pictures Entertainment, the parent company, first to pull the film and then announce selected screenings after being hacked by cyber-terrorists working for the North Korean government.   The reports from CNN and other news organizations were a bit more interesting than the book, mainly because Cadegan deals with past censorship of another age while Sony’s predicament is in the here and now and will have far-reaching consequences in our global culture going forward.   The bottom line is that no state or church should be allowed to practice censorship in a country that accepts the right to free speech as sacred.   Yet, here ...

ECMAScript 6: new OOP features besides classes

This blog post is outdated. Please read chapter “ New OOP features besides classes ” in “Exploring ES6”. Classes [2] are the major new OOP feature in ECMAScript 6 [1] . However, it also includes new features for object literals and new utility methods in Object . This blog post describes them. New features of object literals Method definitions In ECMAScript 5, methods are properties whose values are functions: var obj = { myMethod: function () { ··· } }; In ECMAScript 6, methods are still function-valued properties, but there is now a more compact way of defining them: let obj = { myMethod() { ··· } }; Getters and setters continue to work as they did in ECMAScript 5 (note how syntactically similar they are to method definitions): let obj = { get foo() { console.log('GET foo'); return 123; }, set bar(value) { console.log('SET bar to '...

One JavaScript: avoiding versioning in ECMAScript 6

What is the best way to add new features to a language? This blog post describes the approach taken by ECMAScript 6 [3] , the next version of JavaScript. It is called One JavaScript , because it avoids versioning. Versioning In principle, a new version of a language is a chance to clean it up, by removing outdated features or by changing how features work. That means that new code doesn’t work in older implementations of the language and that old code doesn’t work in a new implementation. Each piece of code is linked to a specific version of the language. Two approaches are common for dealing with versions being different. First, you can take an “all or nothing” approach and demand that, if a code base wants to use the new version, it must be upgraded completely. Python took that approach when upgrading from Python 2 to Python 3. A problem with it is that it may not be feasible to migrate all of an existing code base at once, especially if it is large. Furthermore, the approach is not ...

Wild

Image
I was worried when I heard Reese Witherspoon say in interviews that she decided to make a film of Cheryl Strayed’s book, Wild:   From Lost To Found on the Pacific Crest Trail (Vintage, 2012) because she was looking for properties with strong female leads.   Although Strayed would qualify as a strong, female character, I would hate to think of a book as a property or as simply a sound career move for an actress looking for an Oscar-worthy part.   Making a film should be making art for art’s sake, but maybe I am being too much of a snob.   Still, I refuse to see a film of a book I love, and in the case of Wild I’ve refused and won’t because I do love the book. In all its constituent parts, Wild is a standard mid-stream reflection on a life in crisis.   Like Dante in his Dark Wood, Strayed finds herself in her late 20s, dabbling in heroin and self-destructive behaviors, facing a disintegrating marriage, and most significantly, absorbing the death of her mother. ...