Christian Heilmann

Freddy vs JSON – Lots of noise about OO JavaScript

Tuesday, February 21st, 2006 at 10:28 pm

It is amazing how something dormant for a long time in the developer community emerges simultaneously at different spots.

My own Show love to the object literal was basically intended to explain the OL as a coding style and syntax allowing your scripts to be self-contained.

Dustin Diaz had a similar post cooking for quite a while and released his JSON for the masses a day later. His post is very enthusiastic about the whole subject, but does confuse some matters.

As always, and through the wonders of remote scripting (yes, I coined that term for comments being added at other people’s blogs linking to your own) a lot of discussions arose. Once again the hardliners of OO development tried to get JS to follow the same rules as higher programming languages, whereas JavaScript novices got very excited about some inconsistencies that might actually prevail as a myth for a longer time now. It is amazing how JavaScript sits in the middle of the whole development spectrum and everybody has an own – very fixed – idea about what good JS is. I got one, too, and there is a draft here about that subject (Hint: It does what it is supposed to do, and is easy to maintain by the intended audience).

Read all about how Dustin and me got informed about what is wrong or what is good about what we said:

Now here is my view on the matter:

The object literal

I like the OL as a syntax, and explained why in the post: It could be a signal that a script is more modern and was developed with unobtrusivity (hah! I guess nobody used that one yet) in mind. It is high time to find a mean for JavaScript novices to spot what is good to use these days and what is debris from the DHTML days. We could also call all our scripts “beta”, that’d also make them smack of Web 2.0!

Jason, err JSON

I like JSON as a data format, but it is not the same as the OL. JSON is a subset of the OL, and basically is a scripting syntax version of XML: It is there to hold data to send it back and forth in a readable and easily convertible way. JSON allows and encourages things like:

var data={
‘my wedding’:’fat and Greek’,
‘Plan’:’9 from outer space’,
‘Red Hot Chili Peppers’:’Flea, Anthony, and many random others’
}

This would be quite confusing in a script, although you can read out data['my wedding'] all the same. I’d consider it harmful as part of a script, as it does not quite promote valid variable names.

How about this: Calling JSON and the OL the same thing is as misleading as calling XML and semantic markup the same thing. One is data, the other is good practice (yes, you are allowed a different opinion).

And what about OO JavaScript then?

Now, if you want to go down and dirty with the real OO of JavaScript, then Tim Scarfe comes to your rescue with these two wonderful articles.

Share on Mastodon (needs instance)

Share on Twitter

Newsletter

Check out the Dev Digest Newsletter I write every week for WeAreDevelopers. Latest issues:

Dev Digest 146: 🥱 React fatigue 📊 Query anything with SQL 🧠 AI News

Why it may not be needed to learn React, why Deepfake masks will be a big problem and your spirit animal in body fat! 

Dev Digest 147: Free Copilot! Panel: AI and devs! RTO is bad! Pi plays!

Free Copilot! Experts discuss what AI means for devs. Don't trust containers. Mandated RTO means brain drain. And Pi plays Pokemon!

Dev Digest 148: Behind the scenes of Dev Digest & end of the year reports.

In 50 editions of Dev Digest we gave you 2081 resources. Join us in looking back and learn about all the trends this year.

Dev Digest 149: Wordpress break, VW tracking leak, ChatGPT vs Google.

Slowly starting 2025 we look at ChatGPT vs Google, Copilot vs. Cursor and the state of AI crawlers to replace web search…

Dev Digest 150: Shifting manually to AI.

Manual coding is becoming less of a skill. How can we ensure the quality of generated code? Also, unpacking an APK can get you an AI model.

My other work: