1 Answer
1

It's because (AFAIK) you cannot put expression as an ID in the hash constructor, because they're automatically quoted as strings.

In other words, this is valid JavaScript

$(this).load(url, {name: "Foo", age: 13});

The keys name and age are there. In JavaScript you don't have to quote the keys of a hash, although in strict JSON the quoting is necessary for keys. (But the quoting wouldn't hurt. And in some cases, as Jordan suggested in the comments, it's necessary e.g. you want to use reserved words like var as the hash key)

Quoting the keys is necessary in some cases--for example IE6 falls over if you use a reserved word as a key, so if you try { class : "some-value" } it will puke because "class" is a reserved word. I think IE7+ and other modern browsers are relieved of this affliction.
–
JordanDec 4 '09 at 17:15

clever one-liners? we do not aim to achieve clever code. you've posted the proper way to do it. remember that it's easier to write code than to debug it, so if you're writing as clever code as you can, you won't be clever enough to debug it yourself later.
–
David HedlundDec 4 '09 at 17:16

2

@David Hedlund: I agree; though I think all of us here are secretly thrilled when they think of clever one-liners. C'mon, admit it :p
–
kizzx2Dec 4 '09 at 17:21

Thanks for the info! You pointed me in the right direction.
–
RandyLaheyDec 4 '09 at 17:38