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

116
Visualizações
Assigning objects to { } in Javascript and Hardhat

Consider the following code snippet:

let { networkConfig, getNetworkIdFromName } = require('../helper-hardhat-config')
const fs = require('fs')

module.exports = async ({
    getNamedAccounts,
    deployments,
    getChainId
}) => {
const { deploy, get, log } = deployments
const { deployer } = await getNamedAccounts()
const chainId = await getChainId()
let linkTokenAddress
let vrfCoordinatorAddress

if (chainId == 31337) {
    let linkToken = await get('LinkToken')
    let VRFCoordinatorMock = await get('VRFCoordinatorMock')
    linkTokenAddress = linkToken.address
    vrfCoordinatorAddress = VRFCoordinatorMock.address
    additionalMessage = " --linkaddress " + linkTokenAddress

    ...........
    ...........

In Javascript, I understand how objects are assigned to variables. eg x = {one: 1, two: 2 } but I don't understand how const { deploy, get, log } = deployments in the above code works. Just to experiment with, on the console I entered the following lines {var1,var2}={one: 1, two: 2 } but the variable var1 and var2 came as Undefined. I am just trying to understand how it is possible, for example, to use the get property as a function as in let linkToken = await get('LinkToken')

Thanks in advance !

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

0

It's called object destructuring, check about it here https://www.freecodecamp.org/news/javascript-object-destructuring-spread-operator-rest-parameter/

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