JavaScript is nice, but weird

I’ve been slowly learning JavaScript over the last few months, and just got bit by something that I think is a mistaken design. I bet it’s bit everyone for whom it’s not their first Algol-like language.

The problem came up with an image that had an “undefined” src property.

I could see it was undefined in Firebug. When the page loads it’s not not undefined. I click on it, and boom it loses its definition. How could that be.

Well, you could have assigned it an undefined value. Let’s look for an assignment. Found it.

Search on Google. Aha. The weirdness. You can call a function with fewer parameters than it defines. The unspecified parameters are (ta dahh) undefined.

Even C, the most laissez-faire language in AlgolLand doesn’t allow this!

Once I knew what I was looking for I found it right off, fixed it, and all is good. :-)

Adventures in programming with Uncle Davey.

About these ads

About Dave Winer

Dave Winer, 54, pioneered the development of weblogs, syndication (RSS), podcasting, outlining, and web content management software; former contributing editor at Wired Magazine, research fellow at Harvard Law School, entrepreneur, and investor in web media companies. A native New Yorker, he received a Master's in Computer Science from the University of Wisconsin, a Bachelor's in Mathematics from Tulane University and currently lives in Berkeley, California.
This entry was posted in Uncategorized. Bookmark the permalink.

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