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

154
Visualizações
creating review carousel from medium.io website
var itemClassName = "carousel__photo";
    items = d.getElementsByClassName(itemClassName),
    totalItems = items.length,
    slide = 0,
    moving = true;

I saw this part of the code on the medium.com website while creating a review carousel. how did they declare this variable? I can not understand this declaration and they use d instead of document how? and why? I am a beginner... if you need more information kindly visit medium.com site .bcuz of your clarity I added only the part I got confused

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

That article has used IIFE JavaScript functions. you could read more about that concept from the link that original article said or from any other tutorial like this one. simply it is a way of running a function without need to call it in your code. for better understanding I converted the script of original article to a normal function.

this is the article code:

(function(d)
    { 
        var itemClassName = "carousel__photo";
        items = d.getElementsByClassName(itemClassName),
        totalItems = items.length,
        slide = 0,
        moving = true;

        console.log(itemClassName);
    })
(document);

And this is the code I converted:

let documentVar = document;
function carousel(documentArgu) {
    var itemClassName = "carousel__photo2";
        items = documentArgu.getElementsByClassName(itemClassName),
        totalItems = items.length,
        slide = 0,
        moving = true;

        console.log(itemClassName);
}

carousel(documentVar)

In the converted version you need to call carousel(documentVar) function to run it. But in the article code you do not need to call function. using IIFE has other advantages also that you can read more from tutorials. But about your question that why d stands for document, the reason is that you could pass IIFE function arguments in the last parenthesis and that means the argument d used in function(d) is the same document that was defined in (document) in the last of article code.

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