My objective is to develop a prototype that can extend various classes. I am tasked with creating a class that extends either Mesh or Points of THREE.js. The subclass I have created is identical for both scenarios and cannot be an interface.
class PointsElement extends THREE.Points {
public name: string
protected width: number
protected height: number
constructor (protected target: THREE.Scene | THREE.Group, protected properties: IElementProperties) {
super()
this.name = this.properties.name
AutoBind(this)
}
public async preload () {
}
public async show () {
this.target.add(this)
}
public async hide () {
this.target.remove(this)
}
}
class MeshElement extends THREE.Mesh {
public name: string
protected width: number
protected height: number
constructor (protected target: THREE.Scene | THREE.Group, protected properties: IElementProperties) {
super()
this.name = this.properties.name
AutoBind(this)
}
public async preload () {
}
public async show () {
this.target.add(this)
}
public async hide () {
this.target.remove(this)
}
}
My goal is to optimize the code by removing the 'Element' suffix, as the content remains the same in MeshElement and PointsElement, despite each class extending different base classes.