Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

shallow-extend

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

shallow-extend

A utility function similar to 'extend()' in underscore or lo-dash

  • 0.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

shallow-extend

browser support

A utility function similar to extend() in underscore or lo-dash.

function extend(destination /*...sources*/) {/*...*/}

Copies properties of all sources to the destination object overriding its own existing properties. When extending from multiple sources, fields of every next source will override same named fields of previous sources. Returns the destination object.

Makes only a shallow copy of the source feilds, in contrast to node-extend or node-deep-extend.

Examples

Merge and modify:

var source1 = {a: 1, b: 1, c: 1};
var source2 = {b: 2, c: 2};
var source3 = {c: 3};

var destination = extend(source1, source2, source3);
// destination --> source1
// source1 --> {a: 1, b: 2, c: 3}
// source2 --> {b: 2, c: 2}
// source3 --> {c: 3}

Do not modify anything:

var source1 = {a: 1, b: 1, c: 1};
var source2 = {b: 2, c: 2};
var source3 = {c: 3};

var destination = extend({}, source1, source2, source3);
// destination --> {a: 1, b: 2, c: 3}
// source1 --> {a: 1, b: 1, c: 1}
// source2 --> {b: 2, c: 2}
// source3 --> {c: 3}

Managing defaults:

function takesOptions(opts) {
    var params = extend({
        a: 'default value',
        b: 'default value'
    }, opts);

    // proceed with params
}

Keywords

FAQs

Package last updated on 01 Jun 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc