umdjs / umd

UMD (Universal Module Definition) patterns for JavaScript modules that work everywhere.
MIT License
7.42k stars 423 forks source link

if(false) { var define; } overites the global `define` in IE - nodeAdapter.js #48

Open duzun opened 10 years ago

duzun commented 10 years ago

I had this issue before with IE. Take a look at this code:

    var x = 10; 
    function a(){ return x; try{}catch(x){} }; 
    alert(a()); // 10 in V8, undefined in IE

In IE (not sure until which version), if a variable is declared anywhere in the scope (inside any block, even a false if), it is available everywhere in that scope, even before its declaration.

Therefore this code overwrites define in environments like IE:

    if (typeof module === 'object' && typeof define !== 'function') {
         var define = function (factory) {
             module.exports = factory(require, exports, module);
         };
    }
szepeviktor commented 10 years ago

If you use ```javascript the code gets highlighted.

duzun commented 10 years ago

Thanks for advice, szepeviktor

:-)
tejacques commented 9 years ago

You can use one of these variations of UMD instead:

https://gist.github.com/tejacques/202a8f2d198ddd54a409 https://gist.github.com/wilsonpage/8598603

Instead of defining a var define, it's passed in as a function argument instead.