recipeswithbackbone / recipeswithbackbone.github.com

Marketing site for the best damn backbone.js book evar
23 stars 1 forks source link

Ambiguous Conclusion - Page 29 #54

Closed kevinseelbach closed 10 years ago

kevinseelbach commented 10 years ago

I'm reading the book now and it seems like the two last paragraphs are worded strangely..

You say 'Even if you are fairly certain that your Backbone application is going to remain small'... you should initialize inside a common namespace object..

The next paragraph goes on to say that if you think your application will grow large, you should use JavaScript's function constructors.

Page 23 also says that global namespace objects lends itself well to large applications split into several files, and that if your application is more 'self-contained' (not sure what this means) that a full-blown JavaScript object makes more sense.. This approach involves using a function constructor.

ngauthier commented 10 years ago

Hi Kevin,

It would be great if we could always package the parts of our app that are "private" into a function, that way other scripts couldn't reference the insides. As long as the source code is physically small (i.e. the line count) it's nice to put it inside a function like on page 29.

As an app gets bigger, a single file is unwieldy, so we break it up into multiple files. Now it's not possible to put the code into a function to hide it, so namespaced classes is the best we can do.

Finally, even when it's small and a single function, you should namespace that function anyways so there aren't collisions.

Hope that helps!

@ngauthier

p.s. I'm closing the issue, but feel free to reopen it if you have further questions!