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

134
Vistas
Acessing Multiple Functions Inside Single Function In an Object

So I Have The Code as Follows:

const Solver = new Object
Solver.circle = function(r){
area = Math.PI * r**2
perimeter = Math.PI * 2*r 
return "Area:" + area + " Perimeter:" + perimeter
}

Now I Would Like To Get the value of area and perimeter seperately like using Something like this

Solver.circle(2).area  \\ 12.57
Solver.circle(2).perimeter \\ 12.57
Solver.circle(2)  \\ Area:12.57 Perimeter:12.57

Is there any way i could achieve something like this. If Not What could be the best Alternative Other than having different Main Functions like Solve.circlearea(2) or Solve.circleperi(2)

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

0

Sure! Just return an object!

const Solver = new Object
  Solver.circle = function(r){
  area = Math.PI * r**2
  perimeter = Math.PI * 2*r 
  return {area, perimeter}
}

Note that you can also do return {area: area, perimeter: perimeter}, but it is not necessary and JS will understand you even if you don't do that. So here you are just returning an object and in your usage you are calling the function and accessing the property from the returned object.

If you replace your function with this, your API example will work as is!

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