Links
Twitter
Flickr
« Javascript prototypes | Main | Souad Massi's album Deb is damn fine »
Thursday
Jan312008

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');


http://www.datejs.com/

Reader Comments (3)

It may point out females’ need Coach Outlet store purses just like bass wants drinking water. Preaching with regards to Coach Totes is like chatting regarding the very best. Your Coach manufacturer is perfect for the best within regarding most totes manufacturers. It is almost always females’ dynamics to save and acquire a higher valued item for example Coach Handbags.

November 8, 2011 | Unregistered Commenterrsstephen

He had again begun to forget this history, when, in the course official timberland boots of March, 1824, he heard of a singular personage who dwelt in the parish of Saint-Medard and who had been surnamed "the mendicant who gives alms." This person, the story ran, was a man of means, whose name mens timberland boots no one knew exactly, and who lived alone with a little girl of eight years, who knew nothing timberland 6 inch premium about herself, save that she had come from Montfermeil. Montfermeil! that name was always coming up, and it made Javert prick up his ears. an old beggar police spy, an ex-beadle, to whom this person had timberland 6 inch boot women given alms, added a few more details. This gentleman of property was very shy,-- never coming out except in the evening, speaking to no one, except, occasionally to the poor, and never white timberland boots allowing any one to approach him. He wore a horrible old yellow frock-coat, which was worth many millions, being all wadded with bank-bills. This piqued Javert's curiosity in a decided manner. In order to get roll top timberland boots a close look at this fantastic gentleman without alarming him, he borrowed the beadle's outfit for a day, and the place where the old spy was in the habit of timberland 14 inch boots crouching every evening, whining orisons through his nose, and playing the spy under cover of prayer. "The suspected individual" did indeed approach Javert thus disguised, and bestow timberland classic tall boots alms on him. at that moment Javert raised his head, and the shock which Jean Valjean received on recognizing Javert was equal timberland 6 inch to the one received by Javert when he thought he recognized Jean Valjean. However, the darkness might have misled him; Jean Valjean's death was official; Javert cherished very grave doubts; and when in timberland authentic 6inch boots doubt, Javert, the man of scruples, never laid a finger on any one's collar. He followed his man to the Gorbeau house, and got "the old woman" to talking, which was no difficult matter. The old woman confirmed the fact regarding the coat lined with millions, and narrated to timberland roll top womens black him the episode of the thousand-franc bill. ZHC

November 16, 2011 | Unregistered Commentertimberland on sale

PostPost a New Comment

Enter your information below to add a new comment.

My response is on my own website »
Author Email (optional):
Author URL (optional):
Post:
 
Some HTML allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>