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

139
Vistas
How do I interpret this syntax?

I found this snippet of code online:

function cjsDetectionPlugin() {
  return {
    name: 'cjs-detection',
    moduleParsed({
      id,
      meta: {
        commonjs: { isCommonJS }
      }
    }) {
      console.log(`File ${id} is CommonJS: ${isCommonJS}`);
    }
  };
}

I understand that this is perfectly valid JS, but it just doesn't compute in my head. The method cjsDetectionPlugin is returning an object, but what exactly is happening on the line with moduleParsed? Does this resolve into some sort of property name?

And my biggest question is how this object can have a sub-property that calls code (console.log...).

What's going on here? Where can I find the definition for this specific syntax as to learn learn more about it?

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

0

It is called Object Destructuring, refer to the "Unpacking properties from objects passed as a function parameter " section in shared link

following one is using object destructering in function parameter:

function sayMyName({ name }) {
    console.log(`my name is ${name}`);
}

this is equivalent to:

function sayMyName(person) {
    console.log(`my name is ${person.name}`);
}
about 4 years ago · Juan Pablo Isaza Denunciar

0

What you have here is a MDN: Method declaration:

function cjsDetectionPlugin() {
  return {
    name: 'cjs-detection',
    moduleParsed() {
      console.log('some logs');
    }
  };
}

And MDN: Destructuring assignment: Unpacking properties from objects passed as a function parameter:

function moduleParsed(/*begin: parameters*/{
  id,
  meta: {
     commonjs: { isCommonJS }
  }
}/*end: parameters*/) {
      console.log(`File ${id} is CommonJS: ${isCommonJS}`);
}
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