Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

259
Views
¿Cómo resolver un error de constructor ilegal al usar esto como entrada en el constructor?

Tengo el siguiente error:

 TypeError: Illegal constructor at new Car (car.js:15:23) at main.js:7:13

El constructor de automóviles está aquí y en línea.

 constructor(x, y, width, height) { this.x = x; this.y = y; this.width = width; this.height = height; this.controls = new Controls(); this.sensor = new Sensor(this); }

El error se lanza en this.sensor = new Sensor(this);

La creación del objeto coche se ve así:

const car = new Car(2, 100, 30, 50);

¿Alguna idea de por qué estoy recibiendo este error? Creo que debería poder usar this como un parámetro, así que no estoy seguro de por qué se arroja el error

Este es el sensor de clase que estoy usando:

 class Sensor{ constructor(car){ this.car = car; this.rayCount = 3; this.rayLength = 100; this.raySpread = Math.PI / 4; this.rays = []; } update(){ this.rays = []; for(let i = 0; i < this.rayCount; i++){ const rayAngle = lerp( this.raySpread / 2, - this.raySpread / 2, i / (this.rayCount - 1) ); const start = {x : this.car.x, y: this.car.y}; const end = { x: this.car.x - Math.sin(rayAngle) * this.rayLength, y: this.car.y - Math.cos(rayAngle) * this.rayLength }; this.rays.push([start, end]); } } draw(context) { for(let i = 0; i < this.rayCount; i++){ context.beginPath(); context.lineWidth = 2; context.strokeStyle = "yellow"; context.moveTo( this.rays[i][0].x, this.rays[i][0].y ); context.lineTo( this.rays[i][1].x, this ); context.stroke(); } } }
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!