From e3a42c8342bba0db15e2ca9a78911121e5d539da Mon Sep 17 00:00:00 2001 From: polo Date: Thu, 29 Jan 2026 22:51:19 +0100 Subject: =?UTF-8?q?classe=20CalendarModalView,=20contr=C3=B4les=20getEleme?= =?UTF-8?q?ntOrThrow=20et=20assertElementType?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- public/js/main.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 public/js/main.js (limited to 'public/js/main.js') diff --git a/public/js/main.js b/public/js/main.js new file mode 100644 index 0000000..50eedf6 --- /dev/null +++ b/public/js/main.js @@ -0,0 +1,16 @@ +// js/main.js + +// réussite de getElementById +function getElementOrThrow(id) { + const elem = document.getElementById(id); + if (!elem) { + throw new Error("l'élément d'id: " + id + " non trouvé"); + } + return elem; +} +// l'erreur attribut "value" non trouvé devient l'élement attrapé n'a pas le bon type (c'est un peu plus clair) +function assertElementType(elem, ctor) { + if (!(elem instanceof ctor)) { + throw new Error(`type attendu: ${ctor.name}, type obtenu: ${elem.tagName}`); + } +} -- cgit v1.2.3