JavaScript
Unfortunate Syntax Rules
There are two things with the JavaScript syntax that really bothers me. What they have in common is that they force you to remember to add superfluous characters to your code. This makes it really easy to forget to add them, and this may cause syntax errors or bugs.
Sound familiar? Probably. First of all I’m thinking of the fact that
array and object literal values need to be comma separated. It makes
sense, [1, 2, 3] looks good when you write it on one
line. But take a look at the multi-line version:
var a = [ 1, 2, 3 ];
Reflections on Prototypical Inheritance
JavaScript is an object-oriented language. It uses prototypical inheritance instead of the more common class based inheritance, but luckily it—being the flexible language it is—allows one to utilize both methods of inheritance. But why even allow for both when you usually work with class based models? Well, I can’t speak for the people responsible for making that decision, but I will give you some of my thoughts on the subject.
Now then, what is prototypical inheritance? Douglas Crockford described it so well when he tried to defend it
ECMAScript Array Instantiation
There are two ways of instantiating Arrays in EMCAScript (if you
exclude every conceivable hack that you could pull out of your hat
just to show me that there are other ways as well). One[^1] uses the
regular object instantiation syntax, namely new Array and
it’s also possible to omit the new in order to call Array
as a function instead (the latter is simply an alias of the former as
can be seen in the specification). The other way is leaner on the
fingers and is written as [], called the literal
notation[^2].