Essays


Send to Kindle

Learning to do object oriented coding in JavaScript

Just to confess, I haven't been doing object oriented developments for coding in JavaScript. It's partly because the syntax (even philosophy) for expressing objects are very different from C++, which I code mostly at work. I was lazy and did not learn details on how to do OO in JavaScript until recently.

JavaScript is very flexible and there are several ways of coding objects. It actually annoyed me for a while because I was looking for one correct way of doing it. The JavaScript developers found many creative ways in implementing object's polymorphism, blocking private variables and methods from being accessed or overwritten from others, and even using namespaces. I found these pages particularly useful:

So, I've been re-organizing the code for my little tool for the page designer tool so it will be more object oriented. It's a small program, but code is actually starting to get messy. So, I re-started from drawing a domain model:

Well, I guess "thanks god, it's still very simple." So, far I wrapped the entire code with a namespace "OnStyle" to avoid polluting the global namespace, and I also experimented with editor class to implement public and private methods. I should be able to convert everything into loosely coupled objects this weekend. Fun.

Original post: Feb. 3, 2011 | Last updated: Feb. 3, 2011

Previous: OnStyle pre-release ver. 2011012700
Next: OnStyle pre-release ver. 2011020400
Read more

comments powered by Disqus