I'm writing a THREE.js graphics program and I want to set up a BodyPart 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 test outside BodyPart and associating it with the prototype, but the same problem occurs. What's wrong with this 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();