开发者

Is it worth to use prototype or should we use OOP for javascript?

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'v开发者_JS百科e 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?


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.


I was using prototype.js from last one year on a RIA. I am not used to the libraries which you are talking about , but i use jQuery. After learning how to use prototype.js i just avoided jQuery,. I was able to do anything use prototype.js, especially when scope really matters prototype handles it in such beautifully way. You can't find the replacement of bind method provided by prototype in any other libraries. It is very very useful. i suggest you to go with prototype without fear.. it is cool and so easy to handle.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜