title: JS. properties in prototype weird behaviour
body: <p>I'm trying to understand how to make properties work with prototype in a nodejs backed webgame.</p>
  
  <p>Reasoning: Instead of doing something like:<code>Player.attributes.pow.value</code>
  It would be so much easier to read when it's: <code>Player.pow</code> Note: I do not want to use a function because <code>Player.pow()</code> makes you feel like it's doing more than just return a value.</p>
  
  <p>So to test how it works I did a quick mockup and noticed an odd behaviour and although it works not sure if I should be doing this:</p>
  
  <pre><code>function Player() {
      this.attributes = { 
      pow: {
        base: 3, 
        value: 3, 
        attChanges: [], 
        multiplier: 0,
        calculateValue: function() {
          var multiplier = this.multiplier;
          var value = 0;
          this.attChanges.forEach( function(att) {
            value += att.value; // For some reason this.value returns NaN in the forEach, this is a way around that...
            multiplier += att.multiplier; 
          });
          this.value = this.base + value;
          this.value *= (1 + multiplier / 100);
        }
      }
    }
    //Change a attribute and calculate it's value
    this.attributes.pow.attChanges.push({value: 3, multiplier: 0});
    this.attributes.pow.calculateValue();
  }
  
  Player.prototype.sayHello = function() {
    console.log("hello");
  }
  
  Player.prototype = {
      get pow() {
      return this.attributes.pow.value;
      }
  }
  
  var p = new Player();
  
  p.sayHello(); // Error
  console.log(p.pow);
  console.log(p.pow);
  p.sayHello();
  </code></pre>
  
  <p>It says <code>TypeError: p.sayHello is not a function</code></p>
  
  <p>But if I put it below defining the property, it works</p>
  
  <pre><code>Player.prototype = {
      get pow() {
      return this.attributes.pow.value;
      }
  }
  
  Player.prototype.sayHello = function() {
    console.log("hello");
  }
  
  var p = new Player();
  
  p.sayHello(); // hello 
  console.log(p.pow); // 6
  console.log(p.pow); // 6
  p.sayHello(); // hello
  </code></pre>
  
  <p>What's going on here? Is this a bad way of doing it? I saw an example of this here: <a href="https://stackoverflow.com/questions/14047809/js-defineproperty-and-prototype">JS defineProperty and prototype</a> It is the second answer at the moment.</p>