Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Personally, I think you are doing quite a good job already, just some small things needed to be improved. First, you should move your namespace to a separate file rather than put it in the same file with your work like this. I would recommend you put it in <code>namespace.js</code>. Next, the is quite very important as well, you should check whether the current namespace exist or not. Your code above always declares new variable. This is quite a serious problem especially when your colleague has already declared the namespace and put some properties to that namespace, your code will completely override your colleague, and you will always get error when you pull your colleagues' code. I would suggest:</p> <p>In <code>namespace.js</code>:</p> <pre><code>var window.MyNameSpace = window.MyNameSpace || {}; MyNameSpace.variable = "inside mynamespace"; MyNameSpace.level1 = MyNameSpace.level1 || {}; MyNameSpace.level1.level2 = MyNameSpace.level1.level2 || {}; </code></pre> <p>So when you colleagues have already declare the namespace or add some properties to the existing namespace, it won't override the existing one. Let's say your colleagues have already create <code>MyNameSpace</code> and added <code>MyNameSpace.level1 = something</code>. The code above won't override <code>MyNameSpace</code> and <code>MyNameSpace.level1</code>, it just point to current existing namespace and its properties. </p> <p><strong>Note</strong> You have to include the namespace.js before other js file, or you will get <code>undefined</code> error.</p> <p>Hope this help!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload