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