title: Avoiding using magic numbers in JavaScript - alternatives that work with JsHint
body: <p>JSHint's inspections now built into PhpStorm informed me about JavaScript magic numbers and I realise it'll make for clearer code to avoid using them.</p>
  
  <p>I tried this:</p>
  
  <pre><code>var constants = {
      millisecs: 1000,
      secs: 60
  };
  </code></pre>
  
  <p>and also this:</p>
  
  <pre><code>var constants = function () {
      this.millisecs = 1000;
      this.getMillisecs = function () {
          return this.millisecs;
      };
  };
  </code></pre>
  
  <p>JsHint complains about both. </p>
  
  <p>Taking the solution from <a href="https://stackoverflow.com/a/2821987/149998">this answer</a> though works fine:</p>
  
  <pre><code>var constants = (function() {
      var millisecs = 1000,
          defaultMsgsPerSecond = 60;
      this.getMillisecs = function() { return millisecs; };
      this.getDefaultMsgsPerSecond = function() { return defaultMsgsPerSecond; };
  })();
  </code></pre>
  
  <p>Presumably because of the closure. Why is it that this is accepted, whereas the other two suggestions taken from another SO question are not?</p>
  
  <p>Edit: Although not triggering an error, it doesn't actually work. It errors to say constants is undefined. <a href="http://jsfiddle.net/Hu6mu/" rel="nofollow noreferrer">JsFiddle</a>.</p>
  
  <p><em>To clarify - by "works" I mean "doesn't trigger a warning from JsHint"</em></p>