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

134
Visualizações
How to create a new object with the variable value

I have many objects for example lets say one of the object name is flipkart

let flipkart = function() {
  this.name = 'flipkart'
  // other functionality....
}

flipkart.prototype.someFunction = function(someValue) {
    console.log(someValue);
};

this is what I am trying to do I get the object names in variable lets say

let myVariable = 'flipkart';

I want to create a new object or access flipkart object which is already created.

const objFlipkart = Object.create(myVariable);

objFlipkart.someFunction('someValue');

Is there any way to get this working.

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

0

If you look on MDN docs, you can see something about Object.create() where you can insert an object like:

const flipkart = {
    name: 'flipkart',
    someFunction: function(someValue) {
        console.log(someValue);
    }
}

and then make a copy of said flipkart by using Object.create():

const copiedFlipkart = Object.create(flipkart);

where you will then have the functionality with the new (exact same, but stored in a new memory location, so any changes won't affect the original flipkart) you wanted:

copiedFlipkart.name = "A new flipcart";

copiedFlipkart.someFunction('someValue');
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