PageRenderTime 33ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/js/BubbleDots/BubbleDotsApp.js

http://github.com/onedayitwillmake/RealtimeMultiplayerNodeJs
JavaScript | 44 lines | 19 code | 3 blank | 22 comment | 3 complexity | 8f4667500850b9c941fa6a6b1a69429f 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. BubbleDots = (typeof BubbleDots === 'undefined') ? {} : BubbleDots;
  16. /**
  17. * Allows a package to create a namespace within RealtimeMultiplayerGame
  18. * From Javascript Patterns book
  19. * @param ns_string
  20. */
  21. BubbleDots.namespace = function (ns_string) {
  22. var parts = ns_string.split('.'),
  23. parent = BubbleDots,
  24. i = 0;
  25. // strip redundant leading global
  26. if (parts[0] === "BubbleDots") {
  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. };