Hello,
I am currently ‘translating’ a web app from ‘normal’ javascript to OOP javascript.
I have read a lot of theory about functions, objects, methods, inheritance and so on.
But now I am thinking more about what routine to use.
Basicly, I used to have a lot of functions to setup my UI:
checkForFirstLaunch();
loadLanguage();
loadNavigation();
loadImages();
I would just call checkForFirstLaunch(), and if it returned false, I would go to the next step, loadLanguage(), and at the end of that function I would call loadNavigation().
But now, I am using just one object named setup, which contains methods like checkForFirstlaunch, loadLanguage etc.
Here’s an example:
var setup = {
run: function() {
// We check if the app has just been launched for the first time. If true, we have to start downloading some images.
( ls.get( "start" ) == null ) ? this.downloadImages() : this.loadLanguage();
},
loadLanguage: function () {
...
loadNavigation();
},
...
}
But this doesn’t look very sexy, and I feel I am not really using much of the OOP potential here, just translating functions into methods. I thought about perhaps having the methods return true if they where successful, but then my code would just be clustered with if/else code. So what’s a good way to control the ‘flow’ of an application?
Thanks!