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

146
Visualizações
Factory Function JS

enter image description here

Hello, Can someone please explain me this const {r,g,b} = this; Why it has no variable name, if 'this' is the variable name, to what that 'this' pointing to?

function makeColor(r, g, b) {
    const color = {};
    color.r = r;
    color.g = g;
    color.b = b;
    color.rgb = function () {
        const { r, g, b } = this;
        return `rgb(${r},${g},${b})`
    }
}
about 4 years ago · Juan Pablo Isaza
3 Respostas
Responde à pergunta

0

The word 'this' is not a variable. This is a relatively new concept. they call it object destructuring syntax.

about 4 years ago · Juan Pablo Isaza Relatório

0

"this" is a special property of methods. When a function is called as a method of an object, as it is here, "this" refers to that object, in this case the color object, so the color.rgb() method will return the string "rgb(r,g,b)" where the r, g, and b there are the values fed to the makeColor function used to create that object.

about 4 years ago · Juan Pablo Isaza Relatório

0

Variable this not even exits, this is one of the reversed words(such as break, for, function, let etc.), this in context you show directs to color constant, so in context you show this equals to color constant.

More about this at MDN.

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