Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

196
Vistas
this.init no es una función

Estoy haciendo esto para la clase y la prueba que tienen dice que mi constructor no se está inicializando, así que lo busqué y encontré this.init() . Ahora obtengo "this.init() no es una función y no estoy seguro de por qué.

Mi código:

 function CuboidMaker(length, width, height){ const volume = () => { return this.length * this.width * this.height } const surfaceArea = () => { return 2 * (this.length * this.width + this.length * this.height + this.width * this.height) } this.length = length this.width = width this.height = height this.volume = volume this.surfaceArea = surfaceArea this.init() }
about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

¿Es simplemente que no está creando una nueva instancia del constructor?

Además, el volume y el área de surfaceArea son funciones y deben llamarse.

 function CuboidMaker(length, width, height){ const volume = () => { return this.length * this.width * this.height; } const surfaceArea = () => { return 2 * (this.length * this.width + this.length * this.height + this.width * this.height); } this.length = length; this.width = width; this.height = height; this.volume = volume(); this.surfaceArea = surfaceArea(); } const a = new CuboidMaker(1, 2, 3); console.log(a);

about 4 years ago · Juan Pablo Isaza Denunciar

0

Creo que no inicializas tu clase correctamente. Pruebe esta sintaxis:

 class CuboidMaker{ constructor(length, width, height){ this.length = length; this.width = width; this.height = height; } volume(){ return this.length * this.width * this.height } surfaceArea(){ return 2 * (this.length * this.width + this.length * this.height + this.width * this.height) } } let myCuboid = new CuboidMaker(1, 2, 3); console.log(myCuboid.volume()); console.log(myCuboid.surfaceArea());

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda