I am writing a little class and I don’t get it why this doesn’t work:
var Browsertest = {
isIE: /MSIE (\d+\.\d+)/.test(this.getUserAgent()),
getUserAgent: function() {
return navigator.userAgent;
}
};
console.log(Browsertest.isIE);
I get the error that getUserAgent() doesn’t exists/is available (in IE9 and other browsers).
You’re calling the
getUserAgentfunction before it is defined. When usingobject literals, instance members need to be defined before they are used.Two alternatives…
One:
Two: