views:

131

answers:

1

I am a developer for sometime now, and for the past few years I am using prototype framework and it's implementation for OOP, to be used in Javascript. I've used jquery and some other frameworks as well.

I 've been studying how js works and how differs from OOP, as it is a prototype oriented language. In my opinion is in fact a great concept, the prototype oriented language.

Given the right attention to:
- it was how the language was meant to be used, and so therefore is faster, more productive and theoretically, simpler and smoother.
- Every browser has its own implementation for how javascript is supposed to work, making sometimes impossible for having a concise code work in all browsers, or at least the majority.
- Usually those OOP frameworks (dojo.declare(), Js.Class, MooTools, etc) are more than suitable to make a nice work, and they are cross-browsers.

I can't help but wonder, is it worth to start making RIA's using javascript prototype oriented? Or Should I go for Dojo.declare(), js.class or some similar?

+1  A: 

I don't think you must forfeit OOP when you program in JS; I suggest you embrace OOP!

  • I prefer the ExtJS library which provides classes, encourages subclassing, and provides a very nice example of a well-defined class hierarchy.
  • Douglas Crockford provides examples of making member data and member functions private (no protected).
  • Many people use JavaScript's prototype as a vehicle to implement inheritence; again see Douglas Crockford.
  • Polymorphism is easy as JS is not strongly typed.

Also, many of the popular JavaScript libraries abstract browser differences from the developer; you will likely find few "ifs" in your code to compensate for differences in browsers should you choose to use a JS library.

Finally, here are some other good resources from SO.

Upper Stage
Those if's are a great fear to me, lol...
NoProblemBabe
Don't get me wrong, i find oop very dear to me. I just want to hear some opinions.
NoProblemBabe
there are any prototype oriented frameworks for js? Thanks for the answer.
NoProblemBabe
Don't fear them. Pick a library (e.g. jQuery, ExtJS, dojo), pick a debugger (e.g. FireBug), test your code frequently on the major browsers, bookmark http://www.quirksmode.org/, and I think you will find the experience fun!
Upper Stage
All of the frameworks/libraries exploit prototypes - primarily for inheritance; you don't need to worry about finding a library created specifically for prototypes. In fact, you may be programming for weeks or months before you encounter a situation where you need to understand the intimate details of prototypes.
Upper Stage