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

  • Home
  • SEARCH
  • 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 9122877
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T06:12:23+00:00 2026-06-17T06:12:23+00:00

Working with the jQuery extend functionality and have run into a case where I

  • 0

Working with the jQuery extend functionality and have run into a case where I am trying to extend a target object that is undefined. I don’t get any errors but the source object is not extended as expected. I had assumed that jQuery would create a blank object and extend to that but this does not seem to be the case. I can work around this by creating the empty object my self but I am looking for some confirmation that this is the case with jQuery’s extend. I could not find anything in the jQuery Api about the target object being undefined.

EDIT: Sorry I should have included a JSFiddle – Here or see the example below. And in doing so need to modify my question. If you look in the fiddle the options object exists, but the property I’m trying to extend to does not exist. This is where my problem is lying. I am guessing jQuery won’t create the empty property this way. And I would need to add the property to the object manually?

options = {newdata:true};

$("#click").click(function(){
  console.log(options);
  someFunc(options);
});

function someFunc(options) {
  $.extend(options.data, {
    someNewData: true
  });
  console.log(options);
}
  • 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-17T06:12:24+00:00Added an answer on June 17, 2026 at 6:12 am

    Reading the relevant jQuery source file

    target = arguments[0] || {};
    

    The first aregument sent to jQuery.extend is used. If it is falsy or undefined, a new empty object will be created. target is then returned by jquery.extend.

    If you were to do the following:

    var target = undefined;
    var data = {'hello': 'world'};
    jQuery.extend(target, data);
    

    target would still be undefined. If you want to work with a target that may be undefined, you have to use jQuery.extend like so:

    var target = undefined;
    var data = {'hello': 'world'};
    target = jQuery.extend(target, data);
    

    Working off your example code, you need to do this:

    function someFunc(options) {
        options.data = $.extend(options.data, {
            someNewData: true
        });
        console.log(options);
    }
    

    Note how the return value of jQuery.extend is assigned to options.data.

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

Sidebar

Related Questions

I'm working with Jquery in Drupal. I have sets of four blocks that all
I am trying to extend an Object of the following structure (with JQuery in
I am working in jquery with backbone.js and running into the case where i
I get this JS error: jquery-1.5.1.min.js:16Uncaught TypeError: Cannot set property '_renderItem' of undefined d.d.extend._Deferred.f.resolveWithjquery-1.5.1.min.js:16
Still working through JQuery to get data and repopulate portions of a page. Right
I'm working with jquery mobile library... Couple of days a go...I ran into a
I'm working with jquery. And i have text input in a form, i would
I have been working with jQuery mobile 1.0.1. I have a page which drills
I've got this answer working but I'd like to extend it: jQuery UI Datepicker
I have been working on a Meteor app and want to add multi-page functionality

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.