title: Storing reusable constant in namespaces in JavaScript
body: <p>Please don't point me to <a href="https://stackoverflow.com/questions/1535631/static-variables-in-javascript">Static variables in JavaScript</a></p>
  
  <p>My question is more specific. I newbie to JS (just read a couple of books, see some screencasts, and read blog articles about monoins/monads in JS) so be patient ))</p>
  
  <p>To storing reusable constants I write such code:</p>
  
  <pre>
  function SVGobj(w, h) {
      this.value = document.createElementNS(SVGobj.svgNS, "svg");
      this.value.setAttribute("version", "1.2");
      this.value.setAttribute("width", w);
      this.value.setAttribute("height", h);
  }
  SVGobj.svgNS = "http://www.w3.org/2000/svg";
  
  function SVGCircle(cx, cy, r) {
      this.value = document.createElementNS(SVGobj.svgNS, "circle");
      this.value.setAttribute("cx", cx);
      this.value.setAttribute("cy", cy);
      this.value.setAttribute("r", r);
  }
  </pre>
  
  <p>Above code is working. <strong>SVGCircle</strong> reuse constant <strong>SVGobj.svgNS</strong>.</p>
  
  <p>But I don't understand <strong>SVGobj.svgNS =</strong> expression.
  Is that legal use of JS expressions according to JS spec?</p>
  
  <p>Note that such code fail:</p>
  
  <pre>
  var SVGobj = {};
  SVGobj.svgNS = "http://www.w3.org/2000/svg";
  function SVGobj(w, h) {
      this.value = document.createElementNS(SVGobj.svgNS, "svg");
      this.value.setAttribute("version", "1.2");
      ...
  }
  ....
  </pre>
  
  <p>with error:</p>
  
  <pre>
  TypeError: SVGobj.prototype is undefined
  </pre>
  
  <p>when I try instantiate <strong>new SVGobj(320, 240);</strong></p>
  
  <p>Why?</p>
  
  <p>Can I create object by <strong>new</strong> operator but starting from <strong>"var Cls = {};"</strong> expression?</p>
  
  <p>Someone suggest to use:</p>
  
  <pre>
  function SVGobj(w, h) {
      if (typeof SVGobj.svgNS == 'undefined' ) {
          SVGobj.svgNS = "http://www.w3.org/2000/svg";
      }
     ....
  }
  </pre>
  
  <p>Why use <strong>if</strong> which evaluated each time I create object?? My first example seems more natural to me...</p>