I'm trying to understand class and class methods in JavaScript.
The bellow example, works only if you add the keyword static before isIE() method.
1. Why do I need static keyword?
2. How should I change the function, so that I don't need to use static?
class ieAlert {
// Method for checking if IE11
static isIE() {
return window.navigator.userAgent.match(/(MSIE|Trident)/);
}
}
// If the user is using IE11, show the alert
if (ieAlert.isIE()) {
window.alert("Your browser is outdated!");
}
module.exports = ieAlert;