PageRenderTime 106ms CodeModel.GetById 50ms app.highlight 2ms RepoModel.GetById 53ms app.codeStats 0ms

/js/DemoCircles/DemoApp.js

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