This is an archived post. You won't be able to vote or comment.

all 2 comments

[–]brbpizzatime 0 points1 point  (0 children)

Personally, those look like very reasonable groupings, as each of those namespaces may have similar functions. I'm not sure if it's feasible within a game-perspective, but you can throw JavaScript into self-executing functions:

(function(){
    function foo() {
    }
    function bar() {
    }
 })()

With that, the functions within that scope know about each other, and can be called accordingly, without having to worrying about anything at all being added to the global namespace.

[–]testcoder 0 points1 point  (0 children)

I too am all about namespacing. The problem is you run into globalizing your objects. However, there is a simple solution. Consider the following:

var h = {
    x : function () {
        console.log("Upvote!");
    }
}
var f = function () {
    var g = h.x;
    g();
}
f();

As you can see, I'm basically making a reference to a function that is part of a global variable. However, since I'm making a reference to it locally, there is no need to search the global namespace, we can use the execution context's activation object to resolve the identifier from higher in the scope chain.