Skip to content

Instantly share code, notes, and snippets.

@miguelludert
Created August 29, 2012 13:34
Show Gist options
  • Save miguelludert/3512585 to your computer and use it in GitHub Desktop.
Save miguelludert/3512585 to your computer and use it in GitHub Desktop.
Snippet for cross platform javascript modules
(function(){
"use strict";
var result = {}; // your javascript module
if(typeof define !== undefined && typeof define.amd !== undefined ){
define(function(){
return result;
});
} else if(typeof module !== undefined && typeof module.exports !== undefined ){
module.exports = result;
} else {
return result;
}
}());
@LaughingSun
Copy link

of course that doesn't work because typeof returns a string always and your comparisons are against undefined which is not a string.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment