Skip to content

Instantly share code, notes, and snippets.

@mmintel
Last active May 11, 2018 13:22
Show Gist options
  • Select an option

  • Save mmintel/69b7f2630e48523bdecff7f810d402c4 to your computer and use it in GitHub Desktop.

Select an option

Save mmintel/69b7f2630e48523bdecff7f810d402c4 to your computer and use it in GitHub Desktop.
Code snippets für eine Javascript Architektur
// Lade alle Module aus dem Ordner und speicher Sie in der Variable ab
import * as modules from './modules';
class App {
constructor() {
// Speicher die Module in der App
this.modules = {};
}
init() {
// Iteriere durch alle Module, führe jedes Modul aus und
// übergebe die App (this) via Dependency Injection.
Object.keys(modules).forEach((key) => {
this.modules[key] = modules[key](this);
});
}
}
// Wir haben nur eine App, also können wir sofort eine Instanz erzeugen
const app = new App();
// Optional: die App in Window abspeichern,
// damit wir zu Debbugging-Zwecken leicht aus der Browser Console darauf zugreifen können
window.app = app;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment