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

412
Views
¿Cómo usar la función de objeto javascript para devolver un valor y usarlo como propiedad del objeto?

En el precio de venta, espero obtener 1000-20%, es decir, 800 al pasar MRP y descuento como argumentos a la función obtener_precio_de_venta, pero mi código da error obtener_precio_de_venta indefinido obtener_precio_de_venta. Por favor, ayúdenme a arreglarlo y háganme saber por qué sucedió esto, ya que declaré la función antes de usarla.

 let Sock = { brand: 'JS', color: 'Red', size: "extra-extra small", MRP: 1000, discount: 20, get_selling_price: (MRP, discount)=>{return MRP-((MRP*discount)/100)}, selling_price: get_selling_price(this.MRP, this.discount), buy: ()=>console.log(`You are buying ${this.brand}`), sell: function(){console.log(`You are selling ${this.brand}`)}, } console.log(Sock);
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

En JavaScript, si desea acceder a la información almacenada dentro del objeto desde el método del objeto, debe usar la función regular () en lugar de la función de flecha . En su caso, para acceder a la función obtener_precio_de_venta dentro de precio_de_venta del objeto Calcetín, debe definir precio_de_venta como una función normal y acceder a otra función/propiedad del objeto usando esta palabra clave (vea el ejemplo a continuación).

 let Sock = { brand: "JS", color: "Red", size: "extra-extra small", MRP: 1000, discount: 20, get_selling_price: (MRP, discount) => { return MRP - (MRP * discount) / 100; }, selling_price: function () { return this.get_selling_price(this.MRP, this.discount); }, buy: () => console.log(`You are buying ${this.brand}`), sell: function () { console.log(`You are selling ${this.brand}`); }, };

Además, solo para mencionar, te recomiendo que te reconozcan con esta palabra clave en JavaScript, puedes consultar esta documentación: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/this

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!