Re:Common JavaScript Gotchas
by mattmanser on Sunday February 24, 2013 @08:01AM
(#5274042)
The relative simplicity is what I mean about really enjoying writing javascript.
The everything is a function is because at least in other languages it's clear what a constructor is, what a function is and what an anonymous method is. They all look distinctly different and have different keywords or declaration syntax. Generally speaking something like:
class Thing
Thing() { } //constructor
function Thing() {} //function
(p) => {} //anonymous method
Visually they are very different. In javascript they all look pretty much the same and have exactly the same syntax.
Well There are no classes in javascript at all. A constructor is a function in most OO languages. The difference here is the underlying OO implementation.
Anonymous methods are by nature functions as well. Could there be a more succinct syntax for them? Perhaps, but of all of the complaints about javascript this is a relatively minor one.
I would never say that there are not things about JS that don't drive me nuts. But the relatively simplicity of thinking of just about everything being treated equally from a language standpoint gives you a flexibility to work that can be really refreshing.