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

185
Views
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 answers
Answer question

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 Report

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 Report

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 Report
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!