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

187
Vistas
cómo llamar a la función dentro del objeto

Tengo un objeto de la siguiente manera

 var shop = { costPrice: function() { return 100; }, sellingPrice: function() { var calculateProfit = function() { return this.costPrice() * 0.2; } return this.costPrice() + calculateProfit(); } }; console.log(shop.sellingPrice());

Pero esto me da el siguiente error

 objects.html:16 Uncaught TypeError: this.costPrice is not a function at calculateProfit (objects.html:16) at Object.sellingPrice (objects.html:19) at objects.html:22

No estoy seguro de lo que estoy haciendo mal ya que costPrice es una función

about 4 years ago · Juan Pablo Isaza
3 Respuestas
Responde la pregunta

0

calculateProfit debe ser una función de flecha

 var shop = { costPrice : function() { return 100; }, sellingPrice : function() { var calculateProfit = () => { return this.costPrice() * 0.2; } return this.costPrice() + calculateProfit(); } }; console.log(shop.sellingPrice());
about 4 years ago · Juan Pablo Isaza Denunciar

0

 var shop = { costPrice: function() { return 100; }, sellingPrice: function() { var calculateProfit = () => this.costPrice() * 0.2; return this.costPrice() + calculateProfit(); } }; console.log(shop.sellingPrice());

about 4 years ago · Juan Pablo Isaza Denunciar

0

Intenta cambiar estas funciones para que sean flechas:

 var shop = { costPrice : function() { return 100; }, sellingPrice : function() { var calculateProfit = () => { return this.costPrice() * 0.2; } return this.costPrice() + calculateProfit(); } }; console.log(shop.sellingPrice());
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