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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T04:11:53+00:00 2026-05-31T04:11:53+00:00

jQuery has a very neat extend method, which merges 2 objects into one. On

  • 0

jQuery has a very neat extend method, which merges 2 objects into one.

On the jQuery Plugins authoring page they show an example as follows:

var settings = $.extend({
    'location'         : 'top',
    'background-color' : 'blue'
}, options);

However, I’ve seen many plugins pass an empty object as the first parameter, like so:

var settings = $.extend({}, {
    'location'         : 'top',
    'background-color' : 'blue'
}, options);

As far as I can tell, these two do the exact same thing. The only difference would be if the defaults would have been stored in its own variable:

var defaults = {
    'location'         : 'top',
    'background-color' : 'blue'
},
settings = $.extend({}, defaults, options);

This way, you can always access your defaults without them being overridden by the options.


Here’s the question: Why do so many plugin authors opt to pass an empty object to extend, even when they don’t store the defaults in a variable?

Am I missing something?

  • 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-31T04:11:55+00:00Added an answer on May 31, 2026 at 4:11 am

    Possible reasons (for the second example)…

    • Inherited ignorance… (saw it done that way, and copied the practice)

    • Intrinsic ignorance… (saw it done properly as in your last code block, but replaced the cached object with an on-the-fly object and didn’t know that the empty object should be removed)

    • Global warming.

    • Lack of attention to detail… (similar to point 2, knows it isn’t necessary but never really took the time to examine the code)

    • Global cooling.

    • Overly defensive coding… (afraid that the defaults may someday be reworked into a reusable object, and is afraid that the empty object won’t be inserted at that time)

    • jQuery developers always do what the voices tell them 😉

    Overall, you’re right. The middle object is created, copied to an empty object, then discarded. It’s an unnecessary and wasteful practice.

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

Sidebar

Related Questions

The JQuery has method effectively selects all elements where they have particular descendants. I
jQuery has the very cool feature/method .data, I wonder if there is a way
Jquery has utility a function called ' extend ' which can be used to
Drupal has a very well-architected, jQuery -based autocomplete.js . Usually, you don't have to
I have a JSP which has jQuery and wanted to change the action message
If a page has both JQuery and Prototype then I got conflict. There is
I created a page that has a JQuery based dialog using the standard JQuery
hallo all i have a site which has a very big scroll on it,
i having a very weird problem now . I has separate 2 jquery js
jScrollPane has a very reasonable problem when working with tabs. Tabs (both jQuery UI

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.