début de MVC

 Le contrôleur

  1. class Controleur { constructor(view) { this.view = view; this.name = "control" this.bind(); } bind() { console.log(this.name); this.view.bindAdd(()=>this.handlerAdd()); } handlerAdd() { let data = new Date(); this.view.handlerAdd(data); } }
  2. c = new Controleur(new View());

 La view

  1. class View { constructor() { this.name = "view" this.bAdd = document.querySelector(".add"); this.l = document.querySelector("ol"); } handlerAdd(data) { console.dir(this.name); this.l.insertAdjacentHTML("afterbegin", `<li> ${data}</li>`); } bindAdd(handler) { this.bAdd.addEventListener("click", () => { console.log(this.name); handler(); }) } }

 HTML

<body>
    <button class="add" name="buttonAdd" type="submit"> + </button>
    <ol></ol>
    <script src="view.js"></script>
    <script src="controleur.js"></script>
</body>