title: Can't call a function in a Javascript class
body: <p>I'm writing a THREE.js graphics program and I want to set up a <em>BodyPart</em> class in Javascript with some methods - but I can't call those methods. The code below prints 'calling test', but not 'called test'. I've tried putting the function <em>test</em> outside <em>BodyPart</em> and associating it with the prototype, but the same problem occurs. What's wrong with this code?</p>
  
  <pre><code>        function BodyPart (name){        
            this.name = name;
            this.test = function(){
               alert('called test');
               }                
            this.geometry = new THREE.BoxGeometry(1, 1, 1);
            this.material = new THREE.MeshNormalMaterial( { color: 0x00ff00 } );            
            return new THREE.Mesh(this.geometry, this.material);
            }
  
  
          var backFoot = new BodyPart("Back foot");
          alert('calling test');          
  
          backFoot.test();
  </code></pre>