Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

208
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!