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

188
Visualizações
Object.Function (* is not a function)

How would I add a function after an object, without raising the error 'substr is not a function' ?

e.g.

    var country = {
        get: function() {
            return 'USA';
        },
        set: function(value) {
            
        }
    }

    console.log(country.substr(0, 2));
about 4 years ago · Juan Pablo Isaza
3 Respostas
Responde à pergunta

0

You are trying to use substr() in an object that only has .get() and .set(). susbtr() is a method of string, so you can chain it after .get() that actually returns a string:

var country = {
        get: function() {
            return 'USA';
        },
        set: function(value) {
            
        }
    }

    console.log(country.get().substr(0, 2));

about 4 years ago · Juan Pablo Isaza Relatório

0

I am not sure what you mean add a function after an object. But if you want to log the substring of "USA", you are missing the call of the function in your log. Country is an object. It does not have any function substring. You have to define it first. You should call get() function to retrieve the value. It should be:

country.get().substr(0, 2)
about 4 years ago · Juan Pablo Isaza Relatório

0

Country is an object, you can't use substring on an object.

You could do

country.get().subsring(0,2)

On another note, this is very un-javascript like code. Looks like you're trying todo OO programming in javascript.

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