3 things I didn’t know about Javascript until tonight
1.
Arrays and associative arrays as literals in Javascript:
var activityLevels = {
sedentary:[1.15, 1.15],
light:[1.4, 1.35],
moderate:[1.5, 1.45],
very:[1.85, 1.7],
exceptional:[2.1, 2]
}
alert(activityLevels["light"][0]); // => 1.4
2.
Apparently you should use Object rather than Array if you’re creating an associative array:
var hash = new Object();
hash["key"] = “value”;
hash["foo"] = “bar”;
I am aware of the mitigating factors — hell, I just enumerated them — but complaining that Prototype “breaks” your ability to use Array as a hash is like complaining that Prototype “breaks” your ability to use String as a hash. It is not Prototype’s fault that JavaScript does not deter this improper use, and it certainly does not mean that Prototype does not “play well with others.” You are free to reject Prototype and keep using Array improperly, but then you give up your right to bitch and moan.
Thanks Mr. Dupont
3.
Date handling made super-badass-awesome in Javascript:
// Convert text into Date
Date.parse('today');
Date.parse('t + 5 d'); // today + 5 days
Date.parse('next thursday');
Date.parse('February 20th 1973');
Date.parse('Thu, 1 July 2004 22:30:00');