Created
March 4, 2017 21:21
-
-
Save KennethanCeyer/3c78f7c18c3519355509e2174103d633 to your computer and use it in GitHub Desktop.
Javascript module definition with requirejs.
This file contains hidden or 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
<script src="require.js"></script> | |
<script src="main.js"></script> |
This file contains hidden or 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
requirejs.config({ | |
baseUrl: './' | |
}); | |
require(['math'], function(Math) { | |
console.log(Math.sum(1, 2)); | |
}); |
This file contains hidden or 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
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