1

I am using the Lungo framework. I am trying to understand if there is a bug in my code or a bug in the framework because I want to "blame my code before blaming others." This line of code is throwing the following error in Firefox 26.0 -- but not in Chrome 31.0.1650.63:

 _sameSection = function () {
     var dispacher_section, same;
     if (!event || !lng.Element.Cache.section) {  //event is not defined
         return true; 
     }

I know that event is not a reserved word in javascript (Is 'event' a reserved word in JavaScript?) -- but it is a global variable in IE. Is it also a reserved word on Chrome? Because I don't get this error on Chrome.

If I look back through the code, I see that event is not defined as a variable outside of the scope of this function. So it seems like it has to do with how different browsers handle the "event" word.

Community
  • 1
  • 1
bernie2436
  • 22,841
  • 49
  • 151
  • 244

1 Answers1

0

Consider using explicit check instead of implicit:

typeof(window.event) === "undefined"

Different browsers have different behavior about special cases of other browsers (which is why libraries like jQuery is easier - many of the one-off cases are handled inside library already).

Alexei Levenkov
  • 98,904
  • 14
  • 127
  • 179
  • actually that won't well you is "event" is defined or not, only that it's initialized to some value. ("event" in window) is more proper. – dandavis Dec 28 '13 at 19:28
  • @dandavis - not sure what alternative you suggested - can you show the condition? While I agree that my check is not exactly "if `event` is not defined" but but I believe it reasonably close in intent of original `!event` - it will tell that `event` is not defined OR defined to be `undefined` (which distinguish FF/Chrome from IE as probably original code intended). – Alexei Levenkov Dec 28 '13 at 19:42
  • @AlexeiLevenkov that fixed my problem. Can you explain what you mean by "Different browsers have different behavior about special cases of other browsers (which is why libraries like jQuery is easier - many of the one-off cases are handled inside library already)." – bernie2436 Dec 30 '13 at 01:43
  • @akh2103 - check http://www.quirksmode.org. Browsers have they own not-so-standard features either for historical reasons (IE is one with the most, especially since most other browsers force auto-update to latest version) or due to new not yet standardized features. Most developers didn't test code in multiple browsers, so authors of browsers had to decide what "not-standard" behavior to support and if/how to do that. Libraries like jQuery have all necessary (and correctly implemented) checks for large number of such "feature" and provide unified way to code without checking for browsers. – Alexei Levenkov Dec 30 '13 at 06:07