Alex-D / Cookies-EU-banner

1kb vanilla JS script which manages cookies consent banner display like asked by GDPR
http://alex-d.github.io/Cookies-EU-banner/
MIT License
439 stars 57 forks source link

Fix the launchFunction argument when not a function #57

Closed gladchinda closed 4 years ago

gladchinda commented 4 years ago

When constructing the CookiesEuBanner instance, it is possible that the argument passed as the launchFunction named parameter may not be a function.

// Boolean explicitly passed here
new CookiesEuBanner(false);

// Undefined implicitly passed here:
new CookiesEuBanner();

For any of the above scenarios, the code will throw a TypeError indicating that the designated launchFunction is not a function.

Hence, a type check is required to ascertain that the launchFunction is a function. And if not, a no-op function can be used as a fallback.

Alex-D commented 4 years ago

First, I did not understand why you did not use the callback: that's why the plugin is made for... And why did you not just put a noop as first param? I close this as the first parameter is required, and I do not want to make it optionnal.