10/05/2005

JavaScript sucks ass, part one million

In the spirit of Bob Ippolito's JavaScript Sucks posts, here is one of my own. Sit down and let me tell you a tale about the little language that is so close to being good, yet so far...



Recently, I changed jobs. I joined a company called slide, which is building a hybrid photo sharing application using a combination of fat client and rich web technologies. In my drive to create responsive web applications I have been exploring techniques which make heavier and heavier use of client-side JavaScript. I now find myself doing less and less Python and more and more JavaScript rendering code.



I don't really mind this too much. I think JavaScript is a reasonable language, with reasonable anonymous function syntax, real closures with mutable parent scopes, and prototype inheritance (with the most bizarre implementation that unfortunately renders it almost unusable). However, every once in a while I hit some issue which drives me absolutely insane trying to debug.



Here is what I ran in to. The following:



{'foo': 1}


Is not valid syntax. However, the following:



foo = {'foo': 1}


Works fine. I ran in to this issue while trying to eval constructed strings of javascript. Even though eval returns a result, giving it a single JavaScript object literal results in an exception. Tacking on an assignment at the beginning fixes the issue. Ugly.



3 comments:

Bob Ippolito said...

({'foo': 1}) is valid syntax, typically you tack on parens to do JSON.

Donovan Preston said...

Thanks, that helps a lot. Now if only I had known about that yesterday ;-)
But this sort of reinforces the point of my post. This is one of those things that doesn't really make sense and you have to discover for yourself.

hekar said...

javascript is extremely gay and a brand new language has to take its place because it retarded needs to more like php's simple design which even though takes a lot of server processing i still use in place of js