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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T14:28:03+00:00 2026-05-24T14:28:03+00:00

Seems $.extend uses only the keys of its input to determine what to overwrite.

  • 0

Seems $.extend uses only the keys of its input to determine what to overwrite. So when my config looks like this

var config = {
    "numeric" : false,
    "keycode_whitelist" : [
        37, 39, // Left, right
        9,      // Tab
        17,     // Ctrl
        116     // F5
    ]
};

and is extended with more keycodes to add to the whitelist, extend simply overwrites the defaults with the new keycodes one by one even though they are different values.

I’m thinking about solving this problem by typing the keys like this 37: 37, 39: 39 etc. I would love a solution that doesn’t force me to mess up the syntax of my configuration though.

  • 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-24T14:28:03+00:00Added an answer on May 24, 2026 at 2:28 pm

    You might want to use merge instead of extend:

    var config = {
        "numeric": false,
        "keycode_whitelist": [
            37, 39, // Left, right
            9, // Tab
            17, // Ctrl
            116 // F5
        ]
    };
    
    var custom = {
        "somevalue": "some other things",
        "keycode_whitelist": [
            1, 2, 3
            ]
    };
    var newopts = $.extend({}, config, custom);
    newopts.keycode_whitelist = $.merge(custom.keycode_whitelist, config.keycode_whitelist);
    

    Demo: http://jsfiddle.net/3Q4cF/2/

    Update:

    To merge every single array:

    $.each(config, function(key, obj){
        if($.isArray(obj)) {
            if(custom[key]) {
               newopts[key] = $.merge(config[key], custom[key]);
            }
        }
    } );
    

    http://jsfiddle.net/3Q4cF/5/

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

Sidebar

Related Questions

When autoloading in multiple classes that extend the same parent, they seem to overwrite
Seems that This will be an easy question for you but this problem is
Seems like i need some help with a project. I have a routine ,
Seems like there should be... Right now it just seems like magic that you
Seems like cuke doesn't show the full error message (at least when problem occurs
Seems when I make move refactoring all my junit tests lays on its old
My problem is mostly like this: strange out of memory issue , and I
I DON'T WANT TO COMPILE PHP TO NATIVE EXES OR ANYTHING LIKE THAT, ONLY
I'm trying to extend some Swing components and override methods that interacts with its
I've found a script that seems perfect for my needs, but it uses IDs,

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.