Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

185
Visualizações
how do you make an object callable and attach functions to it at the same time

I'm using winston as a logger and in it you have a format namespace and function at the same time, so i can both call format() and access other functions via the namespace format.someFunction() as illustrated in the code below. Now i'm wondering how i can create an object like this myself?

const isRequest = format((info, _opts) => {
    if (info.isRequest) {
        return info
    }
    return false
})

export const logger = createLogger({
    level: 'info',
    format: format.combine(
        format.timestamp({
            format: 'YYYY-MM-DD HH:mm:ss'
        }),
        format.printf((info) => {
            return `${info.timestamp} ${info.level}: ${info.message}`
        })
    ),
    transports: [
        new transports.File({
            filename: errorLog,
            level: 'error'
        }),
        new transports.File({
            filename: requestLog,
            format: format.combine(isRequest())
        }),
        new transports.File({
            filename: combinedLog
        })
    ],
    exceptionHandlers: [
        new transports.File({
            filename: exceptionsLog
        })
    ]
})
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

It's JavaScript function expression. If you export it, it works pretty much the same. Hope this is what you mean.

More about function expression

let sayHello = function() {
  console.log("Hello")
}
sayHello.sayWorld = function() {
  console.log("World")
}

sayHello();
sayHello.sayWorld();

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda