I've been working on a JavaScript project for a while. I've done some pretty major interactivity with web pages before, but not at this level. The amount of JavaScript code I've produced far outways the small amount of Perl code for the backend side.
Some things have really bothered me about this language, though:
1. The + operator.
I know that JavaScript is a mildly variable defined language. (Kupek, what's the word I'm looking for to describe that aspect of the language? An array is defined as such, a number is defined as a number, etc.) However, the conversion is sometimes not very smart.
Take the + operator. Please. Take it. Stop using it for string concatenation, like Perl has. If my statement says:
2. No hashes.
I miss hashes. And I know what you're going to say: "But, Sine, JavaScript is an OO language. You don't need hashes." Fine, I perhaps don't need hashes, but if I'm going to get away without using hashes, I would like to have a .keys method. There is no way to transfer a set of object names to an array without doing:
If I write a statement in a loop like:
4. Getting the last value of an array is bulky
JavaScript requires a lot of code to get to the last value of an array. It's more of a matter of the characters typed, but I just type them so often. Contrast and compare:
5. No destructuring assignments
This is in JS 1.7, but I can't do that for compatibility reasons. It allows you to do this:
6. God, document.getElementById is a lot of fucking characters.
I finally gave up and created a GEBI function.
Some things have really bothered me about this language, though:
1. The + operator.
I know that JavaScript is a mildly variable defined language. (Kupek, what's the word I'm looking for to describe that aspect of the language? An array is defined as such, a number is defined as a number, etc.) However, the conversion is sometimes not very smart.
Take the + operator. Please. Take it. Stop using it for string concatenation, like Perl has. If my statement says:
Code: Select all
I'd expect to see foo equaling 12. Instead, I often see it equaling 84, just because I happened to grab it from an XML set, and it's too stupid to realize that an unquoted 4 means a fucking number. I find myself being paranoid and putting in:
foo = bar + 4; // where bar = 8
Code: Select all
Just to make sure that it's going to actually do MATH, instead of string concats. I could do "bar - -4", but that's fugly.foo = Number(bar) + Number(joe);
2. No hashes.
I miss hashes. And I know what you're going to say: "But, Sine, JavaScript is an OO language. You don't need hashes." Fine, I perhaps don't need hashes, but if I'm going to get away without using hashes, I would like to have a .keys method. There is no way to transfer a set of object names to an array without doing:
Code: Select all
Thus, wasting an array and taking a few more lines of code every time. Sometimes I just need it to check if an object has anything. This is blindly simple in Perl; not so much in JavaScript:
var arr = new Array;
for (var i in obj) { arr.push(i); }
Code: Select all
3. Var should mean "kill it!", but it doesn'tPerl:
if (keys %foo) { do stuff; }
JavaScript:
var data = 0;
for (var i in foo) { data = 1; }
if (data) {
If I write a statement in a loop like:
Code: Select all
I would expect that foo would equal undefined like it does with Perl's my. Except that it doesn't. For some strange reason, the variable is still local to the loop, but it doesn't get destroyed after the loop is done. It still holds the variable and uses the previous value after it sees the "var foo" statement. Instead, I have to use "var foo = undefined;" just to make sure that it's not going to burn me with this confusing rule.while (whatever) {
var foo;
...some code...
if (foo) { do something; }
}
4. Getting the last value of an array is bulky
JavaScript requires a lot of code to get to the last value of an array. It's more of a matter of the characters typed, but I just type them so often. Contrast and compare:
Code: Select all
This wouldn't be so bad if I didn't have to use it so often. There's no such thing as foreach loops, so everything is a typical C-based "for (var i; i < someObj.rows.length; i++)" loop. Maybe just give me a pop method without removing the value from the array.Perl:
$rows[$#rows]
JavaScript:
someObj.rows[someObj.rows.length - 1]
5. No destructuring assignments
This is in JS 1.7, but I can't do that for compatibility reasons. It allows you to do this:
Code: Select all
This is great for functions that returns multiple values.var arr = new Array(5,10,15,30);
[a,b,c,d] = arr;
6. God, document.getElementById is a lot of fucking characters.
I finally gave up and created a GEBI function.
Rosalina: But you didn't.
Robert: But I DON'T.
Rosalina: You sure that's right?
Robert: I was going to HAVE told you they'd come?
Rosalina: No.
Robert: The subjunctive?
Rosalina: That's not the subjunctive.
Robert: I don't think the syntax has been invented yet.
Rosalina: It would have had to have had been.
Robert: Had to have...had...been? That can't be right.
Robert: But I DON'T.
Rosalina: You sure that's right?
Robert: I was going to HAVE told you they'd come?
Rosalina: No.
Robert: The subjunctive?
Rosalina: That's not the subjunctive.
Robert: I don't think the syntax has been invented yet.
Rosalina: It would have had to have had been.
Robert: Had to have...had...been? That can't be right.