Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

makapaka's avatar

What is $.extend in Spark js

As I work my way through Spark I'm trying to actually understand what i'm doing instead of just winging it :)

So in update-contact-information.js we have

data() {
    return {
        form: $.extend(true, new SparkForm({
            name: '',
            email: ''
        }), Spark.forms.updateContactInformation)
    };
},

I want to actually understand what $.extend means in this context ?

0 likes
2 replies
kfirba's avatar

@makapaka I don't own Spark so I'm not sure what dependencies it has but I'm pretty sure this is jQuery's extend() method: https://api.jquery.com/jquery.extend/

Basically, it merges the two given objects. By passing true as the first argument, it will tell jQuery to recursively merge the two given objects.

Basic usage:

let obj1 = { a: 1, b: 2, c: 3 };
let obj2 = { d:4, b: 5 };

$.extend(true, obj1, obj2); -> // { a:1, b:5, c:3, d:4 }

To illustrate what happens when the first argument is true (from the docs):

let object1 = {
  apple: 0,
  banana: { weight: 52, price: 100 },
  cherry: 97
};

let object2 = {
  banana: { price: 200 },
  durian: 100
};
 
// Merge object2 into object1, recursively
$.extend( true, object1, object2 );

// -> {"apple":0,"banana":{"weight":52,"price":200},"cherry":97,"durian":100}

Note that the banana's price is 200 and not 100.

Please or to participate in this conversation.