PageRenderTime 25ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 1ms

/js/DemoCircles/DemoApp.js

http://github.com/onedayitwillmake/RealtimeMultiplayerNodeJs
JavaScript | 44 lines | 19 code | 3 blank | 22 comment | 3 complexity | f96f08e0591b482adb051fc36a453869 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1, MPL-2.0-no-copyleft-exception, BSD-3-Clause
  1. /**
  2. File:
  3. RealtimeMultiplayerGame.js
  4. Created By:
  5. Mario Gonzalez
  6. Project:
  7. RealtimeMultiplayerNodeJS
  8. Abstract:
  9. This is the core module for RealtimeMultiplayerGame contains the namespace, and extend method
  10. Basic Usage:
  11. This class is not instantiated
  12. Version:
  13. 1.0
  14. */
  15. DemoApp = (typeof DemoApp === 'undefined') ? {} : DemoApp;
  16. /**
  17. * Allows a package to create a namespace within RealtimeMultiplayerGame
  18. * From Javascript Patterns book
  19. * @param ns_string
  20. */
  21. DemoApp.namespace = function (ns_string) {
  22. var parts = ns_string.split('.'),
  23. parent = DemoApp,
  24. i = 0;
  25. // strip redundant leading global
  26. if (parts[0] === "DemoApp") {
  27. parts = parts.slice(1);
  28. }
  29. var len = parts.length,
  30. aPackage = null;
  31. for (i = 0; i < len; i += 1) {
  32. var singlePart = parts[i];
  33. // create a property if it doesn't exist
  34. if (typeof parent[singlePart] === "undefined") {
  35. parent[singlePart] = {};
  36. }
  37. parent = parent[singlePart];
  38. }
  39. return parent;
  40. };