Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.