After stumbling upon this code snippet online, I was left scratching my head:
function cjsDetectionPlugin() {
return {
name: 'cjs-detection',
moduleParsed({
id,
meta: {
commonjs: { isCommonJS }
}
}) {
console.log(`File ${id} is CommonJS: ${isCommonJS}`);
}
};
}
While I can see that the JavaScript syntax is correct, I'm struggling to wrap my head around it. In the cjsDetectionPlugin
function, an object is being returned, but what exactly is going on with the moduleParsed
line? Is it translating into a property name somehow?
My main confusion lies in how this object is able to contain a sub-property that executes code (console.log...
).
This leaves me wondering - what's the deal here? Where can I go to delve into the specifics of this syntax and gain a better understanding of it?