Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Aug 3rd, 2012  |  syntax: None  |  size: 0.72 KB  |  hits: 11  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. /*
  2. add a monkey-patched "require" function to the global scope (global object).
  3. It is smarter in two ways:
  4. - It only loads a module once
  5. - If the exports object contains a function matching the module base name, return that
  6.   value from "require" - this is a bit of sugar added because Titanium's require implementation
  7.   does not allow you to replace the "exports" object directly
  8. */
  9.  
  10. //monkey patch "require" in the global scope
  11. require('require_patch').monkeypatch(this);
  12.  
  13. //regular modules are the same...
  14. var module = require('module');
  15. module.sayHello('Marshall');
  16. module.sayGoodbye('Kevin');
  17.  
  18. //modules which contain a type by the same name as the module...
  19. var Person = require('Person');
  20. var jedi = new Person('Luke','Skywalker');