Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I love the whole user experience/interface thing and put a lot of jQuery and JavaScript (pure JavaScript for HTML5 stuff, like canvas, file API, etc). The problem I face now is that my codes are growing large, 3-4 files per project with each file around 1000 lines of code, and maintaining and extending them is becoming a headache.

I know that Object-Orientated JavaScript coding can solve a lot of my problems. I know the basic concepts of Object-Orientated Programming, have done a decent amount of it in C++, Java and Python in school and college projects. I want to read some good examples large scale OO programming in JavaScript (and jQuery), or if possible, some book specifically on writing big OO programs in JavaScript.

EDIT1: Checked out backbone.js, guess thats what i needed, will be sure once i use it in my next project, thanks Raynos, also, my question should have been about handling large js projects, and not what it is, sry

share|improve this question
    
Using custom events is a good way to tackle complexity. –  Karoly Horvath Jul 23 '11 at 22:24
    
Try using organisation libraries like curl/require for modularisation and Backbone/spine/sammy/knockout for MVX style structure. Also I'd recommend you read node.js projects as they have good examples of OO js –  Raynos Jul 23 '11 at 22:55
    
I'd also recommend you only use Object.create and traits for your OO. This along with AMD modules should keep your code tight and structured –  Raynos Jul 24 '11 at 18:10
    
Have a look at JavaScript MVC –  Chiron Jul 24 '11 at 19:50
add comment

3 Answers 3

up vote 2 down vote accepted

Check out backbone.js so far its one of the best solutions (along with javascript mvc) to give some order into the caos/beauty of large scale javascript applications. If you think its overkill I would recommend separating your files in some kind of structure, for instance a file with all of the event bindings, another file for all of the ajax calls another one for anything that edits the html.... if you think about it you are kind of already trying to make a type of mvc structure so check out those tools first and see what they have to offer.

share|improve this answer
    
doing that already, working on my firm's portfolio and it has many different js stuff going on. Hadn't used backbone.js when i started working on it so started making separate files for each piece of work. It has eased the development process a lot, and I can always combine and minify them at the time of production. By the way, from what I have read of backbone.js, its the perfect lightweight addition for at least medium scale apps –  kapv89 Aug 4 '11 at 18:11
add comment

ExtJS is an highly refined, completely extensible library of Javascript UI components that shows the power of OO programming in Javascript. You could also look at the jQuery source, or the Yahoo! UI library.

share|improve this answer
add comment

Google for Scalable JavaScript Architecture. You'll find a lot of resources for what you want. Some of them are:

  1. Nicholas from Yahoo
  2. Nettuts+

Also you can follow JavaScript design patterns in books like Pro JavaScript Design Patterns from Apress.

I also recommend subscribing to the feed of some good sites like:

  1. DailyJS
  2. JavaScript Kit
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.