Can we call() or apply() method instead of bind() for event handlers.
I know we can usenbind() to pass in the context when using the event handler.
var user = {
data : [{name:"first person wood" , age : 45},{name :"Edwards" , age:34}],
click : function(event){
var randomNumber = ((Math.random() * 2 | 0) + 1) -1;
$('input').val(this.data[randomNumber].name + " ,"
+ this.data[randomNumber].age);
}
};
$('button').click(user.click.bind(user));
In the above example we are using bind to pass the user context when the button is clicked. can we use the call() or the apply() to do the same ? If yes, how would we achieve it ?