gh.js 654 B

12345678910111213141516171819202122232425
  1. var gh = gh || {};
  2. /**
  3. * Creates the given namespace if it does not already exist. For example:
  4. * gh.provide('foo.bar.baz');
  5. *
  6. * is equivalent to:
  7. * foo = foo || {};
  8. * foo.bar = foo.bar || {};
  9. * foo.bar.baz = foo.bar.baz || {};
  10. *
  11. * So the following code would execute safely:
  12. * gh.provide('foo.bar.baz');
  13. * foo.bar.baz.count = 0;
  14. *
  15. * @param namespace The namespace to be created.
  16. */
  17. gh.provide = function(namespace) {
  18. namespace = namespace.split('.');
  19. var object = window;
  20. for (var i = 0; i < namespace.length; i++) {
  21. object[namespace[i]] = object[namespace[i]] || {};
  22. object = object[namespace[i]];
  23. }
  24. }