summaryrefslogtreecommitdiff
path: root/public/js/main.js
blob: 50eedf6bfaf17466295bfd822e99fa08c93533b4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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}`);
    }
}