JavaScript: One ID, two functions. How can I do this with minimal code duplication?
Posted
by
user1775598
on Stack Overflow
See other posts from Stack Overflow
or by user1775598
Published on 2013-08-02T15:30:40Z
Indexed on
2013/08/02
15:36 UTC
Read the original article
Hit count: 95
JavaScript
|optimization
I've got an ID and I'd like to assign two functions to it. Here's what it currently looks like:
document.getElementById(this.config.dragArea).addEventListener("drop", this._dropFiles, false);
document.getElementById(this.config.dragArea).addEventListener("drop", this._handleFileDrop, false);
How can I rewrite this file without so much duplication?
I tried doing
document.getElementById(this.config.dragArea).addEventListener("drop", this._dropFiles, this._handleFileDrop, false);
and
document.getElementById(this.config.dragArea).addEventListener("drop", function(){this._dropFiles; this._handleFileDrop}, false);
All to no avail :(
© Stack Overflow or respective owner