/js/DemoHelloWorld/DemoHelloWorld.js
JavaScript | 44 lines | 19 code | 3 blank | 22 comment | 3 complexity | 8b7eba42e9d45fde25833131946ebc8c MD5 | raw file
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 11 Basic Usage: 12 This class is not instantiated 13 Version: 14 1.0 15 */ 16DemoHelloWorld = (typeof DemoHelloWorld === 'undefined') ? {} : DemoHelloWorld; 17/** 18 * Allows a package to create a namespace within RealtimeMultiplayerGame 19 * From Javascript Patterns book 20 * @param ns_string 21 */ 22DemoHelloWorld.namespace = function (ns_string) { 23 var parts = ns_string.split('.'), 24 parent = DemoHelloWorld, 25 i = 0; 26 27 // strip redundant leading global 28 if (parts[0] === "DemoHelloWorld") { 29 parts = parts.slice(1); 30 } 31 32 var len = parts.length, 33 aPackage = null; 34 for (i = 0; i < len; i += 1) { 35 var singlePart = parts[i]; 36 // create a property if it doesn't exist 37 if (typeof parent[singlePart] === "undefined") { 38 parent[singlePart] = {}; 39 } 40 parent = parent[singlePart]; 41 42 } 43 return parent; 44};