title: Javascript prototype constant declaration
body: <p>I am working with a RESTful API, and my Javascript code is making REST queries via jQuery's $.ajax() call.</p>
  
  <p>I have implemented a javascript Rest class, which I will show below (greatly simplified):</p>
  
  <pre><code>var Rest = function (baseUrlPath, errorMessageHandler) {
          ...
      };
  
  // Declare HTTP response codes as constants
  Rest.prototype.STATUS_OK = 200;
  Rest.prototype.STATUS_BAD_REQUEST = 400;
  
  ... // other rest methods 
  
  Rest.prototype.post = function (params) {
          $.ajax({
              type: 'POST',
              url: params.url,
              data: params.data,
              dataType: 'json',
              contentType: 'application/json; charset=utf-8',
              beforeSend: this._authorize,
              success: params.success,
              error: params.error || this._getAjaxErrorHandler(params.errorMessage)
          });
          };
  
  ... // more rest methods
  
  Rest.prototype.executeScenario = function (scenarioRef) {
          var self = this;
  
          this.post({
              url: 'myurlgoeshere',
              data: 'mydatagoeshere',
              success: function (data, textStatus, xhr) {
                  if (xhr.status == 200) {
                      console.log("everything went ok");
                  }
              },
              error: function (xhr, textStatus, errorMsg) {
                  // TODO: constants
                  if (404 == xhr.status) {
                      self.errorMessageHandler("The scenario does not exist or is not currently queued");
                  } else if (403 == xhr.status) {
                      self.errorMessageHandler("You are not allowed to execute scenario: " + scenarioRef.displayName);
                  } else if(423 == xhr.status) {
                      self.errorMessageHandler("Scenario: " + scenarioRef.displayName +  " is already in the queue");
                  }
              }
          });
      };
  </code></pre>
  
  <p>The code works as intended, however I have decided to add some constants to help beautify the code and improve readability. I have for example several places in my code where I am checking for xhr.status == 200 or xhr.status == 400 and so on.</p>
  
  <p>I can declare class variables as <code>Rest.prototype.STATUS_OK = 200;</code></p>
  
  <p>But variable is editable, and I cannot think of how to make them constant. In my code for example I can do a <code>this.STATUS_OK = 123;</code> and this will modify the variable. I have played around with the const keyword, with no luck.</p>
  
  <p>i have seen this: <a href="https://stackoverflow.com/questions/4789323/where-to-declare-class-constants">Where to declare class constants?</a>, but it was not much help.</p>
  
  <p>Can someone point me in the right direction as to how to make these fields a constant literal instead of a variable?</p>