Skip to content

$.extend()

Arthur Guiot edited this page Jul 11, 2017 · 1 revision

How does it work?

This function is SUPER useful when you want to create a function with multiple arguments. This function will merge the arguments the user gave with the default arguments object.

How to use it?

I know it's maybe not clear, so let's take a look at an example 😊!

JS:

var defaults = {
    number: 1,
    bool: true,
    magic: 'real',
    animal: 'whale',
    croutons: 'delicious'
};

var options = {
    number: 2,
    magic: 'real',
    animal: 'porpoise',
    bool: false,
    random: 42
};

var settings = $.extend(defaults, options);

console.log(settings);
// Returns: Object{animal: "porpoise", bool: false, croutons: "delicious", magic: "real", number: 2, random: 42}

⚠️ Questions?

Don't hesitate to ask your questions ⁉️ in the issue part 😁

Clone this wiki locally