View Full Version : OOP in JavaScript

October 28th, 2011, 05:37 PM
Anyway, I have just left Flash in a fit of fury about what happened 5 months ago, so I have decided to start using JavaScript and canvas now! Yay!

I was/am working on a crude XML interpreter that could be expanded to make it easy to make RPGs and Platformers. Well, that sounds completely useless, maybe. Who knows!? It'll be fun as well, maybe. (See http://i.savagewolf.org/DuskWolf.swf and http://i.savagewolf.org/pong.xml )

Anyway, I want to use OOP design thingies in JavaScript, but what I've read of it so far suggests to me it's rather hacky and confusing. But I have heard of those "translator" programs that translate, say, Python to JS (Pyjamas), and am wondering if you wise people would recommend me using them for this, or if they are too slow or complicated, or something. Maybe.

October 29th, 2011, 12:53 AM
If you're into online graphics & games then flash so far is the better choice. The canvas support and 2D drawing speed varies wildly across browsers. Otoh Flash is pervasive and fast enough for certain scenarios.
WebGL requires GL knowledge and is still too bugy and lacks unified sound and keyboard/joystick controls, not to mention IE doesn't support it for political reasons which M$ pretends are technical (security related, which pretty much have already been fixed).
So, if you're going after JavaScript, then yes, it's rather a procedural language than an object oriented one, but I'd still suggest writing code directly in JavaScript rather than using a translator.
My 0.02$

October 29th, 2011, 09:47 AM
OOP in JavaScript is not really hacky, it's just different to what people are used to.


Once you get the hang of prototypes, they're actually quite nice.

In addition to prototype-based OOP, another interesting feature of JS are actually its hints of functional programming. Good JS makes extensive use of both... the language is actually quite far from being plain procedural.

October 29th, 2011, 12:14 PM
Flash is on the way out though. Million dollar companies are already rewriting their Flash websites to HTML to make content accessible on mobile devices.

October 29th, 2011, 11:01 PM
Agreed. Flash is a dying technology. I got out of ActionScript two years ago - a good career decision, I think.