Well, first of all make sure you read this guide by Tappcelerator about using commonJS in Titanium: https://wiki.appcelerator.org/display/guides/CommonJS+Modules+in+Titanium
A bit of a quick background, commonJS is a javascript library for dependency loading in javascript, which makes it easy to break a javascript program into pieces of independent code, each running in it's own scope.
Titanium makes use of commonJS from version 1.8 of the SDK. and using it gives you great clean code, breakable into defined pieces, running in their own scoped, and very great for performance.
in Titanium you could use this in one of the following ways: (1) you either make a module with function that you can call from the object requiring them (which is pretty much like static methods), or (2) you have the entire module act as an object with it's own functions (prototyped) and exposed by one function.
for example:
Module (myModule.js):
function sayHello(name) {
alert('Hello ' + name);
}
exports.sayHello = sayHello;
App (app.js):
var myModule = require('/myModule');
myModule.sayHello('developer82');
the other way to do that (and this one I think is what you're looking for):
Module (myView.js):
function myView() {
var some_view = Ti.UI.createView({ /* properties */ });
// your logic comes here
return some_view;
}
module.exports = myView;
App (app.js):
var myView = new (require('/myView'))();
of course there are other ways to go about this like creating something that you can require and implement something like createMyView function (see peracetic inheritance).
hope this answers you question.