Skip to content

Instantly share code, notes, and snippets.

@kwhinnery
Created October 31, 2011 17:20
Show Gist options
  • Save kwhinnery/1328057 to your computer and use it in GitHub Desktop.
Save kwhinnery/1328057 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