if none of the two terms in the title tell you anything, you have some serious reading todo.
first off learn and love coffeescript.
second of all get to know some javascript design patterns. why? because it helps you to write a lot better clearer code in a very weird language.
so my design pattern of choice is revealing module…obviously…as the title already spoiled ;)
how to implement it in coffescript?
i wont do much explaining…so here is the code
CoolModuleNamedAfterTheControllerOrPageIuseItIn = -> ultraSecretLocalVar = 42 loadKittyImages = -> console.log("Meow!") loadFunnyImageSlider = -> console.log("Swooosh!") doSomething = -> console.log("Yes, we can!") publicMethod1 = -> doSomething() return initView = -> loadKittyImages() loadFunnyImageSlider() return publicMethod1: publicMethod1 initView: initView root = exports ? this root.CoolModuleNamedAfterTheControllerOrPageIuseItIn = CoolModuleNamedAfterTheControllerOrPageIuseItIn()
and thats basically all you need to know. (sorry no coffeescript highlighting yet). it took me a while to figure the exports thingy out, but once you built this you can simply call it with something like this:
this also plays very nice with encapsulating your javascript for different views in different files.
i hope this saved you some time and/or was a helpful pointer.
have fun