Home > Software design >  I am trying to use arguments of one function to another as a prarmeter ,using .bind
I am trying to use arguments of one function to another as a prarmeter ,using .bind

Time:04-14

Hello there i am here trying to use the arguments of one function to parameters of another function.What i am doing here is?I am passing a score for both a and b that results to win or loose with the score i give as a argument,now i want to use that arguments to print out total score for me ,using .bind method.

var club = {
     score : function(a,b){
       
        if (a>b){
            return ('win');
        }
        else if (a<b){
            return ('lose');
        }
    }
}
var germann = function(a,b,c){
    console.log('yourmatch is: ' this.score(a,b));
    };
var germannteam = germann.bind(club);

germannteam(4,2);

So now what can i do to get print out as total of (4,2) = 6

CodePudding user response:

you can add a method to club which do the calculation for this object and return the total

var club = {
  score: function(a, b) {

    if (a > b) {
      return ('win');
    } else if (a < b) {
      return ('lose');
    } else {
      return 'equality';
    }
  },
  total: function(a, b) {
    return (a > b) ? a   b : (a < b) ? a - b : 0;
  }
}
var germann = function(a, b, c) {
  console.log('yourmatch is: '   this.score(a, b));
  console.log('your score is: '   this.total(a, b));
};
var germannteam = germann.bind(club);

germannteam(2, 4);
germannteam(4, 2);
germannteam(4, 4);

  • Related