Valiant attempt, but there are a number of issues with this post.
Author talks about the different ways to declare a function, but doesn't actually come out and say "function statement vs function expression", and doesn't mention hoisting of function statements. He also recommends always using function expressions because of "syntax problems once you get into closures", but never brings up the potential syntax problems.
Telling people to avoid this is bad advice. Users will run into code that uses this and understanding its semantics is fundamental to understanding the OO parts of JavaScript.
In the section about this, author fails to mention the important pitfalls: failing to use new with a constructor and changing scope due to nested functions.
Using var x = new Object(); is nonidiomatic; var x = {}; is the prefered way to instatiate a new object.
Author answers his own question to why JavaScript has so many ways to do different things with "Because JavaScript is a poorly designed language in a lot of ways." I bristled at this statement and it took a bit of reflection to understand why since I don't entirely disagree. My problem is that I don't think the author is in a qualified position to make that statement. Saying something is "poorly designed" assumes knowledge of the design goals and in this case I don't believe the author fully understands them. It reminds me of how junior developers often say "this sucks" rather than "I don't understand this".
18
u/[deleted] Feb 23 '13
Valiant attempt, but there are a number of issues with this post.
Author talks about the different ways to declare a function, but doesn't actually come out and say "function statement vs function expression", and doesn't mention hoisting of function statements. He also recommends always using function expressions because of "syntax problems once you get into closures", but never brings up the potential syntax problems.
Telling people to avoid
thisis bad advice. Users will run into code that usesthisand understanding its semantics is fundamental to understanding the OO parts of JavaScript.In the section about
this, author fails to mention the important pitfalls: failing to usenewwith a constructor and changing scope due to nested functions.Using
var x = new Object();is nonidiomatic;var x = {};is the prefered way to instatiate a new object.Author answers his own question to why JavaScript has so many ways to do different things with "Because JavaScript is a poorly designed language in a lot of ways." I bristled at this statement and it took a bit of reflection to understand why since I don't entirely disagree. My problem is that I don't think the author is in a qualified position to make that statement. Saying something is "poorly designed" assumes knowledge of the design goals and in this case I don't believe the author fully understands them. It reminds me of how junior developers often say "this sucks" rather than "I don't understand this".
And a couple of nitpicks:
I dislike Allman style indentation (and it's fairly nonidiomatic in JavaScript).
Author should use
jsdeclaration around his code blocks for enhanced readability, e.g.:This will make github render the code with js syntax highlighting.