title: Javascript - Object State
body: <p>I may be approaching this incorrectly...</p>
  
  <p>I'm trying to keep track of an objects state internally and use it to call modified methods:</p>
  
  <pre><code>createObject = function() {
    this.a = 1
  
    this.method1 = function() {
    if (this.a == 1 ) {
      //do stuff
      this.a = 0
    }
  }
  
  var x = new createObject()
  </code></pre>
  
  <p>Unfortunately, state isn't being internally tracked.  If I change the properties of another object it works perfectly however:</p>
  
  <pre><code>otherObj = { a:1 }
  
  createObject = function() {
  
    this.method1 = function() {
    if (this.a == 1 ) {
      //do stuff
      otherObject.a = 0
    }
  
  }
  
  var x = new createObject()
  </code></pre>
  
  <p>Is this the correct way to approach this?</p>