0

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?

1 Answer 1

2

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 ).

Sign up to request clarification or add additional context in comments.

2 Comments

Dear god... Thank you so much for this!!! I was so focused on the logic in my methods...
You're welcome. You should use the console (F12) on your navigator to debug errors. (you should also validate the answer if it suits you).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.