Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Entity classes are not extendable #257

Open
xLuxy opened this issue Sep 15, 2024 · 3 comments
Open

Entity classes are not extendable #257

xLuxy opened this issue Sep 15, 2024 · 3 comments

Comments

@xLuxy
Copy link
Collaborator

xLuxy commented Sep 15, 2024

When executing the code below you'll receive the following error message:
(Note: same error can be observed even without ompatibility mode. Other entity classes also seem to be affected)

 [JSv2]   TypeError: col.myMethod is not a function
    at file:///C:/Users/xLuxy/Desktop/altv-test-server/resources/core/server/index.js:34:5
    at ModuleJob.run (node:internal/modules/esm/module_job:194:25) 
import alt from 'alt-server';

class MyCustomColshape extends alt.ColshapePolygon {
  constructor(min: number, max: number, points: Array<alt.IVector3>) {
    super(min, max, points);
  }

  public myMethod() {
    alt.log('myMethod');
  }
}

const col = new MyCustomColshape(0, 0, [
  { x: 0, y: 0, z: 0 },
  { x: 10, y: 0, z: 0 },
  { x: 0, y: 10, z: 0 },
]);

col.myMethod();

alt.log(col);
@xLuxy xLuxy changed the title v1 compat entity classes prototype chain issue Entity classes are not extendable Sep 16, 2024
@Yiin
Copy link
Contributor

Yiin commented Sep 22, 2024

does it work in js-v1?

@a-zzura
Copy link

a-zzura commented Sep 22, 2024

does it work in js-v1?

Yes, it worked on v1, I used it in my project.

@xxshady
Copy link
Collaborator

xxshady commented Nov 6, 2024

Temporary workaround:

const col = new MyCustomColshape(..)
Object.setPrototypeOf(col, MyCustomColshape.prototype)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants