title: How to set private member of javascript object
body: <p>I have a dog class that contains private members with public methods to access these members using closure.</p>
  
  <pre><code>class Dog {
  
  constructor(name,  age,  avail) {
  
      var _name, _age, _availability;
  
      _name = name;
      _age = age;
      _availability = avail;
  
      this.getName = function () {
          return _name;
      }
  
      this.getAge = function () {
          return _age;
      }
  
      this.getAvailability = function () {
          return _availability;
      }
  
  }
  
  Dogs[0] = new Dog("Macy","6 Years", true);
  </code></pre>
  
  <p>I want to be able to change the able to change the _availability member.
  I tried adding:</p>
  
  <pre><code>        this.setAvailbility = function (param) {
          if (param == "false") {
              _availability = false;
          } else if (param == "true") {
              _availability = true;
          }
  </code></pre>
  
  <p>but that didn't work.  How can I go about doing this?</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>class Dog {
  
    constructor(name, age, avail) {
  
      var _name, _age, _availability;
  
      _name = name;
      _age = age;
      _availability = avail;
  
      this.getName = function() {
        return _name;
      }
  
      this.getAge = function() {
        return _age;
      }
  
      this.getAvailability = function() {
        return _availability;
      }
      this.setAvailbility = function(param) {
        if (param == "false") {
          _availability = false;
        } else if (param == "true") {
          _availability = true;
        }
      }
  
    }
  }
  
  var dog = new Dog("Macy", "6 Years", true);
  dog.setAvailbility("false");
  console.log(dog.getAvailability())</code></pre>
  </div>
  </div>
  </p>