Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8642575
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T11:48:41+00:00 2026-06-12T11:48:41+00:00

Is it possible to convert the following four anonymous jquery functions into one function

  • 0

Is it possible to convert the following four anonymous jquery functions into one function that gets a parameter passed?

this is what I have…

    dropZone.addEventListener("dragenter", this.dragEnter, false);
    dropZone.addEventListener("dragover", this.dragOver, false);
    dropZone.addEventListener("dragleave", this.dragLeave, false);
    dropZone.addEventListener("drop", this.dragDrop, false);

…

this.dragOver = function(ev) {
    ev.stopPropagation();
    ev.preventDefault();
    this.className = "dragover";
}

this.dragLeave = function(ev) {
    ev.stopPropagation();
    ev.preventDefault();
    this.className = "dragleave";
}

this.dragEnter = function(ev) {
    ev.stopPropagation();
    ev.preventDefault();
    this.className = "dragenter";
}

this.dragDrop = function(ev) {
    ev.stopPropagation();
    ev.preventDefault();
    this.className = "dragdrop";
}

I’m looking for something functionally similar to…

    dropZone.addEventListener("dragenter", dropEvent(this,"dragenter"), false);
    dropZone.addEventListener("dragover",  dropEvent(this,"dragOver"), false);
    dropZone.addEventListener("dragleave", dropEvent(this,"dragLeave"), false);
    dropZone.addEventListener("drop",      dropEvent(this,"dragDrop"), false);

…

function dragEvent(ev, label) {
    ev.stopPropagation();
    ev.preventDefault();
    this.className = label;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T11:48:43+00:00Added an answer on June 12, 2026 at 11:48 am

    You can do that using a partially-applied function:

    function dragEvent(that, label) {
      return function(ev) {
        ev.stopPropagation();
        ev.preventDefault();
        that.className = label;
      }
    }
    

    You can read more about partial application in javascript here: http://benalman.com/news/2012/09/partial-application-in-javascript/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is it possible to convert the following XML configuration to an annotation based one?
Is it possible to convert HTML + CSS into HTML for a system that
Is is possible to convert following into a simpler more readable linq or lambda
Is it possible to convert the following into HQL 3.0.5 using any approach? Subqueries,
How would I convert the following into a one liner? I know it is
Is it possible to convert the following into a list comprehension? cleaned_list = []
Possible Duplicate: Convert one date format into another in PHP I have a date
Is it possible to convert the following script so that it can be called
Is is possible to do the following using nginx rewrite: Convert a url from
Is it possible to convert a FF Jetpack extension to a chrome's one? I've

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.