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

211
Visualizações
Why 'this.userid' is assigning undefined value? does "this" pointing to the class or the object itself? timestamp_generate_function() works though

Why 'this.userid' is assigning undefined value? does "this" pointing to the class or the object itself? timestamp_generate_function() works though.

class price_update {


    constructor(api_key, url_endpoint, user_id, store_name) {
        this.api_key = api_key;
        this.url_endpoint = url_endpoint;
        this.userid = user_id;
        this.store_name = store_name;
    }

    #updatePriceQuantity_parameters = {
        Action: "UpdatePriceQuantity",
        Format: "json",
        Timestamp: this.#timestamp_generate_function(),
        UserID: this.userid,
        Version: "1.0"
    };
about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

does "this" pointing to the class or the object itself?

In this case, this refers to the object. No, not the JavaScript's object ({}) data type, but the instance of the price_update class when instantiated with new price_update().

Oh, right, you have a typo there (user_id1 instead of user_id in the constructor parameters). user_id was not defined there (even though the SO mods edited the question), hence undefined.

Snippet of the original post:

class price_update {


    constructor(api_key, url_endpoint, user_id1, store_name) {
        this.api_key = api_key;
        this.url_endpoint = url_endpoint;
        this.userid = user_id;
        this.store_name = store_name;
    }

    #updatePriceQuantity_parameters = {
        Action: "UpdatePriceQuantity",
        Format: "json",
        Timestamp: this.#timestamp_generate_function(),
        UserID: this.userid,
        Version: "1.0"
    };
about 4 years ago · Juan Pablo Isaza Relatório

0

does "this" pointing to the class or the object itself? Yes. this points to the object itself.

Why 'this.userid' is assigning undefined value? You are attempting to set the value based on a property (this.userid) before you've ever defined it (either in the constructor or anywhere else).

Instead, you will want to do something like this in your constructor:

class price_update {


    constructor(api_key, url_endpoint, user_id, store_name) {
        this.api_key = api_key;
        this.url_endpoint = url_endpoint;
        this.userid = user_id;
        this.store_name = store_name;
        this.#updatePriceQuantity_parameters.UserID = user_id;
    }

    #updatePriceQuantity_parameters = {
        Action: "UpdatePriceQuantity",
        Format: "json",
        Timestamp: this.#timestamp_generate_function(),
        UserID: '',
        Version: "1.0"
    };

Note that we're setting the value in the constructor while we're inside of the instance of the object itself. You can do it like this, or in another method if you like. Either way, you have to instantiate the object first before you and access/apply properties that you have set during construction.

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