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

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

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 Denunciar

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 Denunciar

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 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