Blog DavTar

November 21, 2007

Getting Used to a Prototype-based Language

Filed under: Programming — cygnl7 @ 1:40 am

My current position at Move Networks affords me the opportunity to learn more about Javascript. I am quite familiar with class-based object-oriented languages. For some reason it is taking me more effort than I’d like to wrap my brain around using a prototype-based language like Javascript. I mean, I get it but I still don’t see the full usefulness of it (unless really the whole deal is to make it easier to manipulate objects directly; is that really all there is to it?).

Anyway, in my search for understanding I’ve come across a number of ways people use Javascript in class-like ways. But what bugs me about doing this is the inconsistency in how you define your objects or classes or whatever you want to do. Adding methods to an object’s prototype to make them public, switching to object-literal notation, etc. It all just looks ugly to me. So I’ve come up with the following. It’s a mix and match of various methods I’ve seen out there (which are mainly summarized in the comments on a YUIblog post (thank you Eric Miraglia and all those who replied to his post!). I certainly hope people who know more about javascript can comment on whether this looks like a good or bad practice.

(more…)

Advertisements

Create a free website or blog at WordPress.com.