Last active
February 11, 2024 22:25
-
-
Save normanzb/6fd8be315616cec8c47201a38dc9aac1 to your computer and use it in GitHub Desktop.
typical usage example of amd 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
// 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'); | |
}; | |
}); |
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
define(['module1'], function(module1){ | |
return function(){ | |
module1.test(); | |
console.log('done'); | |
}; | |
}); |
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
define(function(){ | |
return { | |
test: function(){console.log(1)}; | |
}; | |
}); |
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
<!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