Skip to content

Merge two or more objects together. A vanilla JavaScript equivalent of jQuery's .extend() function.

License

Notifications You must be signed in to change notification settings

lfurzewaddock/extend

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

extend

Merge two or more objects together. A vanilla JavaScript equivalent of jQuery's .extend() function.

Download extend


Want to learn vanilla JavaScript? Check out "The Vanilla JS Guidebook" and level-up as a web developer. 🚀


Getting Started

1. Include extend on your site.

Include the code in your script, or load it as an external file.

var extend = function () {
	...
};

2. Extend your objects

Pass in two or more objects to extend. For a deep or recursive merge, set the first argument to true.

// Example objects
var object1 = {
    apple: 0,
    banana: { weight: 52, price: 100 },
    cherry: 97
};
var object2 = {
    banana: { price: 200 },
    durian: 100
};
var object3 = {
    apple: 'yum',
    pie: 3.214,
    applePie: true
};

// Create a new object by combining two or more objects
var newObjectShallow = extend( object1, object2, object3 );
var newObjectDeep = extend( true, object1, object2, object3 );

Browser Compatibility

extend works in all modern browsers, and IE 6 and above.

How to Contribute

Please review the contributing guidelines.

License

The code is available under the MIT License.

About

Merge two or more objects together. A vanilla JavaScript equivalent of jQuery's .extend() function.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published