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

209
Vistas
Trying to copy function using .bind()

Here i am trying to get the if() statement used in variable bayern with the help of .bind() ,but all i get is 'your match is undefined'.


     var club = {
    name : 'name',
    result :function(a,b) {
        if (a>b){
            console.log('Win');
        }
        if (a<b){
            console.log('lose');
        }
    }
}

var bayern = function (){
    console.log('your match is : ' + this.result());
}.bind(club);

bayern(4,3);// i gave it as a score a=4,b=3.

this is the error i am getting

your match is undefined
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

As T.J. Crowder already said in a comment, you need to pass the parameters a and b to your function result. Futhermore, you probably wan't to interpolate the result into the output, hence you should return it.

Following a working implementation:

var club = {
    name: 'name',
    result: function(a,b) {
        if (a>b){
            return 'win';
        }
        if (a<b){
            return 'lose';
        }
    }
}

var bayern = function (a,b) {
    console.log('your match is : ' + this.result(a,b));
}.bind(club);

bayern(4,3);
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