Python Programmers Writing Javascript Beware

Call me silly for not reading the docs, but this bug was very hard to find. Dictionaries in python are NOT the same thing in javascript. The curly braces mean it’s an "object literal" and the keys don’t need the quotation marks. For example:

var x = { NAME: 123, Something: "ok"}

Is the same as the following code:

var x = {}
x['NAME'] = 123
x['Something'] = "ok"

Which means that if you had a variable named "NAME" and you expected it’s contents to be the key, then you’re going to have a royally hard to find bug (especially when developing for an already obfuscated framework such as Google Wave).

This is even worse because JSON causes you to believe the quotation marks are needed. If there’s a place to file a JS enhancement proposal, I would, but I doubt this inconsistency would annoy anyone but a pythonista.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s