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 566239
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T12:57:22+00:00 2026-05-13T12:57:22+00:00

I have written a plugin with the following signature: jQuery.fn.attach = function(element, settings, duration,

  • 0

I have written a plugin with the following “signature”:

jQuery.fn.attach = function(element, settings, duration, options, callback) {

Here element is a jQuery object, settings are my custom settings for my plugin and duration, options and callback are all parameters that I use in jQuery’s animate, like this:

someObject.animate({ someCSS }, duration, options, callback);

Now, my question is: Is it possible to make this function easier to call? For instance, right now, to get everything to work as I expect… I have to include all parameters and set the parameters that I don’t use to null:

$(this).attach($('#e1-blue'), null, 3000, null, function() { alert('done'); });

It would be nice to also be able to call this as:

$(this).attach($('#e1-blue'), 3000, function() { alert('done'); });

and as this (ofc)…

$(this).attach($('#e1-blue'), 3000);

Any suggestions?

  • 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-05-13T12:57:23+00:00Added an answer on May 13, 2026 at 12:57 pm

    The simplest thing I can think of is re-ordering the parameters such that the most commonly used ones come first. So if you change the function to:

    jQuery.fn.attach = function(element, duration, callback, settings, options) {
    

    then you can make everything (except probably the first parameter) optional by putting default values into the function body. Such as:

    if(!duration)
       duration = 3000;
    

    Then

    $(this).attach($('#e1-blue'), 3000, function() { alert('done'); });
    

    and

    $(this).attach($('#e1-blue'), 3000);
    

    would both be valid, with the other values automatically populated with null.

    Strictly speaking, you could check for parameter types inside the function e.g. if the second paramter is an integer then it’s the duration, if it’s a function it’s callback, if it’s an object it’s settings, but I don’t think people who have to follow your code later will thank you for it. It could also make the function difficult to extend later down the line if e.g. a second integer parameter was required.

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

Sidebar

Related Questions

I have a AutoCAD 2008 plugin written in VB.NET. This plugin uses mostly the
I have the following situation, I'm using jquery and I need to sum up
I have written a plugin system that uses an interface and for any plugins
I have a plugin written that is registered for the DeliverIncoming message on the
I've written an outlook plugin that retrieves the sender's SMTP email address for a
I'm following a tutorial which I think is written by someone who doesn't know
I have a very strange issue that only affects webkit browsers for some reason,
I have recently ditch Dreamweaver as my IDE for my web projects and I'm
I am trying get tree view in the web page. I am using jstree
I would like to retrieve the dateFormat from my datepicker default set up declaration

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.