Skip to content
This repository has been archived by the owner on Oct 21, 2022. It is now read-only.

Commit

Permalink
Only expose loadJS on the global object if module is undefined. Play …
Browse files Browse the repository at this point in the history
…more nicely with commonjs
  • Loading branch information
scottjehl committed Nov 3, 2015
1 parent 0cc6187 commit de294c2
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions loadJS.js
@@ -1,9 +1,9 @@
/*! loadJS: load a JS file asynchronously. [c]2014 @scottjehl, Filament Group, Inc. (Based on http://goo.gl/REQGQ by Paul Irish). Licensed MIT */
(function( w ){
w.loadJS = function( src, cb ){
var loadJS = function( src, cb ){
"use strict";
var ref = window.document.getElementsByTagName( "script" )[ 0 ];
var script = window.document.createElement( "script" );
var ref = w.document.getElementsByTagName( "script" )[ 0 ];
var script = w.document.createElement( "script" );
script.src = src;
script.async = true;
ref.parentNode.insertBefore( script, ref );
Expand All @@ -14,6 +14,9 @@
};
// commonjs
if( typeof module !== "undefined" ){
module.exports = w.loadJS;
module.exports = loadJS;
}
else {
w.loadJS = loadJS;
}
}( typeof global !== "undefined" ? global : this ));

0 comments on commit de294c2

Please sign in to comment.