In IE 8, the second version of this causes the following error:
Object doesn’t support this property or method.
The error is at map = new L.Map. In the first version, there are no errors.
I thought if you don’t include var it automatically goes to global scope. Why would an error occur in IE 8? Note, this doesn’t happen in IE 9.
var map;
jQuery(document).ready(function()
{
map = new L.Map('map', {'scrollWheelZoom': false});
...
}
VS:
jQuery(document).ready(function()
{
map = new L.Map('map', {'scrollWheelZoom': false});
...
}
This is incredibly bad practice because there is no way to tell whether you intended that. It also causes an error in strict mode.
It also causes bugs in IE when you have some element with the name
mapon the document.You can explicitly create a global like this:
Here you make your intent clear and won’t get this error.
Here are the jsfiddles to demonstrate it (Run in IE8 or lower):
http://jsfiddle.net/3Jn5N/ works
http://jsfiddle.net/3Jn5N/1/ doesn’t work