Přidat otázku mezi oblíbenéZasílat nové odpovědi e-mailem Nejde nastavit const v JS

Tady jsem našel script pro nějaké notifikace.
minimal-notification-popup-pure-javascript
Je tam napsané, že mám

1) Vytvořit novou instanci.

const myNotification = window.createNotification({
      // options here
});

2) Zobrazit vyskakovací okno s vlastní zprávou.

myNotification({
  title: 'Title',
  message: 'Notification Message'
});

Pak je tam nějaké další nastavení.

myNotification({
  closeOnClick: true,
  displayCloseButton: false,
  positionClass: 'nfc-top-right',
  onclick: false,
  showDuration: 3500,
  theme: 'success'
});

Když to tedy vytvořím podle návodu a vložím do stránky

const myNotification = window.createNotification({
      // tady nic nemam
});

myNotification({
  title: 'Úspěch',
  message: 'Úspěch',
  theme: 'success'
});

myNotification({
  title: 'Chyba',
  message: 'Chyba',
  theme: 'error'
});

tak se zobrazí notifikace ale obě jsou zelené (tedy theme je vždy nastaveno na success). Kde dělám chybu? Díky

Předmět Autor Datum
Podle zdrojového kódu to musí být nastavené v createNotification.
Wikan 28.09.2019 20:11
Wikan
Musím tedy před každým vytisknutí notifikace nastavit createNotification? const myNotification = wi…
J.án 28.09.2019 20:27
J.án
const successNotification = window.createNotification({ theme: "success" }); successNotification({ t…
Wikan 29.09.2019 08:31
Wikan
Díky ;-) poslední
J.án 29.09.2019 21:42
J.án

Musím tedy před každým vytisknutí notifikace nastavit createNotification?

const myNotification = window.createNotification({
//nastaveni
});

Celé to tedy bude takhle?

const myNotification = window.createNotification({
  theme: 'success'
});

myNotification({
  title: 'Úspěch',
  message: 'Úspěch',
});

const myNotification = window.createNotification({
  theme: 'error'
});

myNotification({
  title: 'Chyba',
  message: 'Chyba',
});
const successNotification = window.createNotification({
    theme: "success"
});

successNotification({
    title: "Úspěch",
    message: "Úspěch"
});

const errorNotification = window.createNotification({
    theme: "error"
});

errorNotification({
    title: "Chyba",
    message: "Chyba"
});

Případně jenom:

window.createNotification({
    theme: "success"
})({
    title: "Úspěch",
    message: "Úspěch"
});

window.createNotification({
    theme: "error"
})({
    title: "Chyba",
    message: "Chyba"
});

Zpět do poradny Odpovědět na původní otázku Nahoru