Var is broken in js because it does not obey sensible semantics
for(var i....
does what you think it does. In every language except javascript it would declare i only inside the loop. In js it declares i in whatever function scope the loop is inside. A = function(){
console.log(this);
}
A.prototype.q = function(b){
this.h = b;
}
imp = new A();
setTimeout(100, imp.q)
//later, in a response to a user event
console.log(imp.h)
prints undefined. Why? because in Javascript the value of this changes. There is literally no other language where this is dynamically (as opposed to lexically) scoped.Don't even get me started on the lack of ints, the lack of static types (which means your IDEs suck).
As for why node decieded to go with js? No idea, though it is one of the things I hate most about node. Haskell would have been a better choice, as would Lua.
Scoping is broken in pretty much all modern dynamic languages.
Take Ruby for example:
i = 10
[1, 2, 3].map{|i| i * 3}
[1, 2, 3].map{|j| j * 3}
puts i # prints 3
puts j # raises undefined local variable
Or let's look at Python: def maybe_append(b=[], n = None):
if not n is None: b.append(n)
return b
print maybe_append(n=20) # prints [20]
print maybe_append(n=30) # prints [20, 30]
So there's only a single instance of [], so that the default argument "grows" over time.setTimeout( 100, imp.q) // DOESN'T DO ANYTHING, 100 is not a function
And if you thought about it for more than a few seconds, you would realize that the behavior of "this" makes sense and is less magical than in other languages. Since "imp.q" is not a function call, it is a reference to a function, you are simply passing in a function. Since javascript "classes" are just objects with function references, you can't somehow decide what object "this" should point at unless it is explicit. In the case of "foo.bar()", it is explicitly "foo". In the case of setTimeout( foo.bar, 100), all setTimeout gets is a function pointer with no notion of what this should be.
Anyway, the rest of your gripes just sound like you don't like untyped languages, which is personal preference and I guess I don't share your preference.
And it may be nice to have 'just objects with function references' when you are writting a few lines of code to validate emails or something like than. When you start pushing 2k lines of code and more than two developers you need much more structure than than that. Anyhow C++, Scala and C# all have reasonable understanding of this. If all you have are function points, don't have this.
If you are trying to be sarcastic, you are not doing it right.
And I've only been using it for a few years. It really isn't hard to get past the bad parts.
Sure you can. Node.js is not even that impressive: similar solutions exist in lots of other languages, Ruby, Python, even Java. The Node guy wrote Node in JS for two reasons: V8 was a good and fast environment, and JS didn't have much existing libraries, so people could start making new async libs.