As I develop a THREE.js graphics program, I am looking to create a BodyPart class in Javascript that includes various methods. However, I have encountered an issue where I am unable to successfully call these methods. Despite the code displaying 'calling test', it does not proceed to show 'called test'. I have attempted to move the function test outside of the BodyPart class and link it to the prototype, but the problem persists. Can you help me identify the error in 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();