Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

117
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda