Skip to content

Instantly share code, notes, and snippets.

@normanzb
Last active February 11, 2024 22:25
Show Gist options
  • Save normanzb/6fd8be315616cec8c47201a38dc9aac1 to your computer and use it in GitHub Desktop.
Save normanzb/6fd8be315616cec8c47201a38dc9aac1 to your computer and use it in GitHub Desktop.
typical usage example of amd module
// this file is generated by r.js, by bundling all modules into one js file.
define('module1', function(){
return {
test: function(){console.log(1)};
};
});
define('main',['module1'], function(module1){
return function(){
module1.test();
console.log('done');
};
});
define(['module1'], function(module1){
return function(){
module1.test();
console.log('done');
};
});
define(function(){
return {
test: function(){console.log(1)};
};
});
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<script src='bundle.js'></script>
<script>
require('main', function() {
main();
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment