Skip to content

Instantly share code, notes, and snippets.

@kazupon
Created December 17, 2012 18:09
Show Gist options
  • Save kazupon/4320463 to your computer and use it in GitHub Desktop.
Save kazupon/4320463 to your computer and use it in GitHub Desktop.
(function () {
// imports
//var _ = this._ || require('underscore');
// common function 1
var add = function (a, b) {
return a + b;
};
// common function 2
var sub = function (a, b) {
return a - b;
};
// exports
this.add = add;
this.sub = sub;
}).call(this);
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<title>Common module</title>
<script type="text/javascript" charset="utf-8" src="./common.js"></script>
</head>
<body>
<script type="text/javascript" charset="utf-8">
console.log('add', add(1, 1));
console.log('sub', sub(10, 1));
</script>
</body>
</html>
var add = require('./common').add;
var sub = require('./common').sub;
console.log('add', add(1, 1));
console.log('sub', sub(10, 1));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment