I was wondering about on how to organise the code on my site, to make it clearer as possible and clearly readable.

I'm organising it with namespace, separating every single section of the page.

For example:

var Header = {
//code relative to the header

var CentralBody = {
//code relative to the CentralBody

//code to execute on doc ready


First of all, I would know if it is a good way to organise code. In second instance, I was thinking about "what must be placed where". I explain: If, for example, I have to assign some tooltip or to bind event with code like

$('someclass').on( 'event' , ... );

where do I have to place this kind of "functions"? Do I have to place them in the concerning namespace? Do I have to place them on document.ready? Or writing functions in namespace and then call them on document.ready?


A conceptual question, those are always tricky.

Organizing by namespace is not a bad idea, though I would lowercase your namespace ( Header -> header etc. )

Furthermore, I would suggest to look into Movel View Controller and let each namespace have a model, view and controller.

The binding of events is in the realm of the controller. So when you initialize the controller, that is where can you do all the binding.

So in document.ready you can call centralBody.init() which could call centralBody.controller.init().

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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