views:

238

answers:

6

I find myself working on an application that started out small but that has increasing amounts of javascript in it.

Currently my code is procedural. However the codebase is growing in complexity and I suspect I am getting into a situation where a more object oriented approach would be appropriate.

I come from a procedural background, and though I have done some object oriented programming in the past, I'm not as comfortable with it. So, I want to do two things: 1) Bone up on my javascript. 2) Bone up on my object oriented programming in general.

I'm wondering if anyone has recommendations for particularly good books that discuss object-oriented programming in javascript. In particular, I'm looking for books that have specific, practical, real-world examples, of how you would apply javascript object-oriented techniques to design problems. (Here is an example of how you'd build a simple shopping basket, etc...)

Thanks in advance for your help!

+1  A: 

No hard copy books that i know, but a very good slide show: http://ejohn.org/apps/learn/

aviv
+4  A: 

JavaScript: The Good Parts is an excellent book in general. Part of it discusses well-known (and recommended) object-oriented patterns, complete with code examples.

danben
+2  A: 

This is not an answer (and so I've marked it "community wiki"), but it's too long for a comment. :-) This is just a note about something to be aware of:

JavaScript is a very object-oriented language. Everything is an object (including some things you can't directly see). But it's not a class-based language. C++, Java, C#, etc., are class-based languages and that's the form of OOP that got all the press for several years. (That's changing now; a lot more functional languages are coming to the fore.)

JavaScript's particular form of OOP is prototype-based (an object can use another object -- any other object -- as the "prototype" from which it gets its default properties and behaviors). But it also has some class-like trappings, not least because it came out when the world was mad for C++ and Java.

There is a trend of people trying to make JavaScript look more like a class-based language. You see this in a lot of JavaScript toolkits. And JavaScript is so powerful that with the occasional niggle, you can totally emulate a class-based language if you want to.

This is (I think) important information to have when deciding what books and such to read about OOP in JavaScript, because some will be about doing it the prototype-based way, others will focus on using JavaScript as though it were a class-based language, etc.

Good luck.

T.J. Crowder
Much thanks for the thoughtful response, and for others' responses also. I will try to keep this in mind. I ended up ordering a couple of the books that have been suggested. Best.
Travis
You get the answer because it was your response that encouraged me to get two books, so that I can refer back and forth.
Travis
@Travis: Glad it was useful for you! And just as well I marked it CW, I'd be feeling guilty otherwise. :-)
T.J. Crowder
A: 

Pro JavaScript Design Patterns is a well-written book about object–oriented programming techniques in JavaScript.

mrydengren
A: 

I read Javascript Objects by Myers and Nakhimovsky ages ago which covers pretty much everything you'll need to know. It's out of print, but there are lots of very cheap secondhand copies available on Amazon

Hmobius