Reputation: 296
I want my javascript file to look like:
var A= A|| {};
var A.B= A.B|| {};
var A.B.C= A.B.C || {};
A.B.C.myFunc = function ()
{};
A.B.C.myFunc.prototype = {
f1: function(){},
f2: function(){}
}
where A is the main namespace, B is one of its sub namespaces and C is one of the namespaces of the B, but at the moment this structure is not able to initiate the sub namespaces. Any suggestions why?
Upvotes: 0
Views: 40
Reputation: 1319
You must not declare the subNamespaces with var
:
var A= A|| {};
A.B= A.B|| {};
A.B.C= A.B.C || {};
Otherwise the javascript interpreter will trigger an error ( you cannot declare a variable with a point : var A.B
is wrong and A is already an object ).
Upvotes: 2