Skip to content

Instantly share code, notes, and snippets.

@KennethanCeyer
Created March 4, 2017 21:21
Show Gist options
  • Save KennethanCeyer/3c78f7c18c3519355509e2174103d633 to your computer and use it in GitHub Desktop.
Save KennethanCeyer/3c78f7c18c3519355509e2174103d633 to your computer and use it in GitHub Desktop.
Javascript module definition with requirejs.
<script src="require.js"></script>
<script src="main.js"></script>
requirejs.config({
baseUrl: './'
});
require(['math'], function(Math) {
console.log(Math.sum(1, 2));
});
define([], function() {
return {
sum: function() {
var total = 0;
for (var idx in arguments) {
total += arguments[idx];
}
return total;
}
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment