How to use properly class with 'this'


I wrote all my class like this example, everything works good.

import * as THREE from "";

class Enemy {
    constructor(sce) {
        this.mesh = new THREE.Object3D();
        let geometry = new THREE.BoxGeometry(50, 50, 50);
        let mat = new THREE.MeshPhongMaterial({
            color: params.color_enemy,
        let enemy = new THREE.Mesh(geometry, mat);

export default Enemy;

My problem is that i use ‘this.mesh’ to access my entity, so when i would like modify the position
i must do this :

let enemy = new Enemy(scene)

What i would like to do is to access directly my entity like this :

For that i must refer “this” to the object itself in my class but i don’t know how…

Could you show me the good syntax ?


In this case you have to derive your class from Object3D. For syntax details, I suggest you have a look how Group is implemented:

Thanks Mugen87 !