Skip to content

Instantly share code, notes, and snippets.

@masahirompp
Last active August 29, 2015 14:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save masahirompp/5189dccc2c931e272486 to your computer and use it in GitHub Desktop.
Save masahirompp/5189dccc2c931e272486 to your computer and use it in GitHub Desktop.
AMD/namespace template
(function(factory){
if(typeof define === 'function' && define.amd){
define(['underscore', 'other1'], factory.bind(this));
}else{
this.module1 = factory.call(this, this._, this.other1);
}
}.call(this, function(_, other1){
'use strict';
// ここに処理を書く
}));
<html>
<head></head>
<body>
<script src="js/lib/underscore.js"></script>
<script src="js/other1.js"></script>
<script src="js/module1.js"></script>
<script>
window.module1.someMethod();
</script>
</body>
</html>
<html>
<head></head>
<body>
<script src="js/lib/require.js"></script>
<script>
require.config({
paths: {
underscore: 'js/lib/underscore'
}
});
require('js/module1');
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment