Skip to content

Instantly share code, notes, and snippets.

@bradenpowers
Forked from kwhinnery/Person.js
Created September 9, 2011 22:45
Show Gist options
  • Select an option

  • Save bradenpowers/1207520 to your computer and use it in GitHub Desktop.

Select an option

Save bradenpowers/1207520 to your computer and use it in GitHub Desktop.
Monkey patch for require in Titanium Mobile
exports.monkeypatch = function(object) {
var scriptRegistry = {},
old_require = object.require;
object.require = function(moduleName) {
if (!scriptRegistry[moduleName]) {
var mod = old_require(moduleName),
moduleRoot = moduleName.split(/[\/ ]+/).pop();
if (typeof(mod[moduleRoot]) === 'function') {
scriptRegistry[moduleName] = mod[moduleRoot];
}
else {
scriptRegistry[moduleName] = mod;
}
}
return scriptRegistry[moduleName];
};
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment