jplehmann/timecalc — pull request #5 by adamstrickland (2013-02-19 15:15:01+00:00)
Title: Suggested file structure refactorings

Here's a quick PR to illustrate a typical OO file structure in JS. Note that I have not really tested this, I just wanted to illustrate the point.

If we're getting picky, there are some qualitative changes I would make (accessing specific DOM elements within the class, for instance), but i'll have to go there a bit later. This should take care of your fcn declaration issues, though, as well as encapsulate the init() functionality without specifically having to call it.

If for some reason due to load order or the like, this constructor mechanism won't work (I think you mentioned that the `init` code needed to be run after `ko.applyBindings`, the a more JavaScript-y way would be to pass a closure containing the `ko.applyBindings` call into the constructor. E.g.

```
function Calculator(options) {
var _callback = options.callback;
...

# bootstrap
self._initalizeSomething();
_callback(self);
self._initializeSomeMoreStuff();
}

return new Calculator({ callback: function (c) { ko.applyBindings(c); } });
```