Last active
August 29, 2015 13:55
-
-
Save jquense/8689961 to your computer and use it in GitHub Desktop.
Mock sm2 as a CommonJs module
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var SoundMan = require('SoundManager').SoundManager | |
, soundMan = require('SoundManager').soundManager | |
//profit! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function(window, _undefined){ | |
if ( window === _undefined ) | |
throw new Error('SoundManager requries a window object!'); | |
// here be the lib code | |
// use can attach what you must to the window object here! | |
if ( typeof module === "object" && module && typeof module.exports === "object" ) { | |
//CommonJs | |
// the "strict" way is to never expose as a global object if possible, so no sm2 on the window | |
// you could still export it via module.exports and also add to window if you want though. no added benefit | |
// unless your app already expects both, which should not be the case | |
module.exports.SoundManager = SoundManager; | |
module.exports.soundManager = soundManager; | |
} else if ( typeof define === "function" && define.amd ) { | |
// AMD - requireJs | |
define( "SoundManager", [], function () { | |
return { | |
SoundManager: SoundManager | |
soundManager: soundManager | |
}; | |
}); | |
} else { | |
//Normal Browser | |
window.SoundManager = SoundManager; | |
window.soundManager = soundManager; | |
} | |
})(window); | |
//-------------------------------- | |
// my file.js | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment