Skip to content

Instantly share code, notes, and snippets.

@zhuochun
Forked from kwhinnery/app.commonjs.js
Created June 14, 2012 13:12
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 zhuochun/2930223 to your computer and use it in GitHub Desktop.
Save zhuochun/2930223 to your computer and use it in GitHub Desktop.
Ti.include, browser, and CommonJS module
//CommonJS style
var mod = require('browser.ti.module');
mod.sayHello('Kevin');
//Ti.include style
Ti.include('browser.ti.module.js');
globalNamespace.sayHello('Kevin');
//This variable will be the public interface
//of the module in a script tag or Ti.include
var globalNamespace = {};
(function (exports) {
exports.sayHello = function(str) {
alert('Hello '+str+'!');
};
}(typeof exports === 'object' && exports || globalNamespace));
<html>
<head>
<script src="browser.ti.module.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript" charset="utf-8">
//browser style
globalNamespace.sayHello('Kevin');
</script>
</head>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment