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

298
Vistas
How to get function name in javascript arrow function?

I want to get a function's name in an arrow function

Actually, if we write

function abc(){
  let funcName = arguments.callee.name
}

But in an arrow function

abc: ()=>{
  let funcName = arguments.callee.name
}

funcName return ''

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

  • Arrow functions do not have an arguments binding. But they have access to the arguments object of the closest non-arrow parent function. Named and rest parameters are heavily relied upon to capture the arguments passed to arrow functions.
function dummy() {
  return (() => arguments.callee.name)(); // dummy
}
  • The value of this inside an arrow function remains the same throughout the lifecycle of the function and is bound to the value of the closest this-providing environment.
const obj = {
  // like a normal function, returns obj - defines like obj.a = function a() {};
  a() { return this },
  // arrow function uses global as this
  b: () => { return this },
};
console.log(obj.a() == obj) // true
console.log(obj.b() == obj) // false
console.log(obj.b() == window) // true
  • Arrow functions can never be used as constructor functions. Hence, they can never be invoked with the new keyword. As such, a prototype property does not exist for an arrow function.

Therefor, the only way to get the name of an arrow function is from accessing the direct reference to it.

const arrow = () => arrow.name;
console.log(arrow()); // "arrow"

const obj = {
  a: () => obj.a.name;
}
console.log(obj.a()); // "a"
over 4 years ago · Santiago Trujillo 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