Javascript: global behavior of variables in IE8

I am using Require.js for my current project.

And I used to download Require.js config with the required variable, for example

require = { paths: { backbone: "libs/backbone-min", bootstrap: "libs/bootstrap.min", jquery: "libs/jquery-1.7.2.min", underscore: "libs/underscore-min", order: "plugins/order", text: "plugins/text", use: "plugins/use" } }; <script src="http://local.gungroo.com/app/js/config.js"></script> 

This worked fine in all browsers.

I recently switched to Coffescript and the generated code is similar to

 (function() { window.require = { paths: { backbone: "libs/backbone-min", bootstrap: "libs/bootstrap.min", jquery: "libs/jquery-1.7.2.min", underscore: "libs/underscore-min", order: "plugins/order", text: "plugins/text", use: "plugins/use" } }; }).call(this); 

But the second is torn in IE8.

IE8 handles "var require" and "window.require" variables differently?

+4
source share
2 answers

From the requirejs parameter document:

Note. It is best to use var require = {} and not use window.require = {}, it will not behave correctly in IE.

This question has been submitted to the requirejs project on github here . The problem reporter (dtanabe) offered some examples of html and script that illustrate the problem. I created a script here containing this sample code. Please note that for IE 9 it works the same as other browsers (e.g. Chrome, Firefox), but when I changed the document mode in the developer tools in IE 8, a problem arose. In response to this question, jrburke (James Burke) added the documentation I mentioned above.

+4
source

In a web browser:

 window.require = 'herp'; // is equivalent to require = 'derp'; 

window is the top level.

0
source

Source: https://habr.com/ru/post/1412941/


All Articles