# How to use properly class with 'this'

**URL:** <https://discourse.threejs.org/t/how-to-use-properly-class-with-this/28296>\
**Category:** Questions\
**Tags:** javascript\
**Created:** [July 23, 2021, 10:33pm UTC](https://discourse.threejs.org/t/how-to-use-properly-class-with-this/28296 "2021-07-23T22:33:09Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![espace3d](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/espace3d/32/26134_2.png) [@espace3d](https://discourse.threejs.org/u/espace3d)\
**Post date:** [July 23, 2021, 10:33pm UTC](https://discourse.threejs.org/t/how-to-use-properly-class-with-this/28296/1 "2021-07-23T22:33:09Z")

</div>

Hi,

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

```javascript
import * as THREE from "https://threejs.org/build/three.module.js";

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);
        this.mesh.add(enemy)
        sce.add(this.mesh)
        }
    }
}

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)`  
enemy. **mesh**.position.set((0,1,2)

What i would like to do is to access directly my entity like this :  
`enemy.position.set((0,1,2)`

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 ?

Thanks.

---

<div class="post-metadata">

**Author:** ![Mugen87](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/mugen87/32/5645_2.png) [@Mugen87](https://discourse.threejs.org/u/Mugen87)\
**Post date:** [July 24, 2021, 8:07am UTC](https://discourse.threejs.org/t/how-to-use-properly-class-with-this/28296/2 "2021-07-24T08:07:45Z")

</div>

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

> <https://github.com/mrdoob/three.js/blob/3a9152af37e7879e5ed41cb60c549e6a78df57aa/src/objects/Group.js>

---

<div class="post-metadata">

**Author:** ![espace3d](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/espace3d/32/26134_2.png) [@espace3d](https://discourse.threejs.org/u/espace3d)\
**Post date:** [July 24, 2021, 8:30am UTC](https://discourse.threejs.org/t/how-to-use-properly-class-with-this/28296/3 "2021-07-24T08:30:36Z")

</div>

Thanks Mugen87 !
