I'm trying to pass arguments to a function, but can't figure out how to do this when method chaining .bind.
I suppose my question is two fold:
1) How do you pass the parameters to the callback function (in this case, printEvent) when you're using bind?
2) Furthermore, how do you actually pass the pointerdown event to the printEvent function?
var app = {
fruit : 'apple',
printEvent: function(event){
console.log(event + this.fruit );
},
eventListeners:function(){
var target = document.getElementById('elementId');
target.addEventListener('pointerdown', this.printEvent(event).bind(this));
}
}
target.addEventListener('pointerdown', this.printEvent.bind(this, 'pointerdown'));?pointerdownevent itself. Right now, your solution only passes in a stringthis.eventwill automatically be passed.