Skip to content

Instantly share code, notes, and snippets.

@kioku-systemk
Last active June 21, 2017 07:11
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 kioku-systemk/7801c591e81ef8ef20958aaed6e4ef30 to your computer and use it in GitHub Desktop.
Save kioku-systemk/7801c591e81ef8ef20958aaed6e4ef30 to your computer and use it in GitHub Desktop.
js module definition
// UMD (Universal Module Definition)
(function(global, factory, name) {
if (typeof define === 'function' && define.amd) { define([], factory); /* AMD*/ }
else if (typeof exports === 'object') { module.exports = factory(); /* CommonJS */ }
else { global[name] = factory(); /* Global*/ }
})(this, function() {
'use strict';
var MyClass = {
hoge: function () {
console.log('test');
}
}
return MyClass;
}, "MyClass");
@kioku-systemk
Copy link
Author

kioku-systemk commented Jun 21, 2017

使うときは、
var MyClass = MyClass || require('./myclass');
MyClass.hoge();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment