Skip to content

Latest commit

 

History

History
76 lines (61 loc) · 1.53 KB

obj_extend.md

File metadata and controls

76 lines (61 loc) · 1.53 KB

syntax

Single object extension

pObj.extend(target, source, [option])

parameters

target: The target object — what to apply the sources’ properties to, which is returned after it is modified.

source: The source object — objects containing the properties you want to apply.

output [optional]: an optional object to define the option of extension.

returns

the target object

syntax

Multiple objects extension

pObj.extends(target, sources, [option])

parameters

target: The target object — what to apply the sources’ properties to, which is returned after it is modified.

sources: The source objects — array of objects containing the properties you want to apply.

output [optional]: an optional object to define the option of extension.

returns

the target object

option

tidy: if tidy = 1, undefined value in object will be ignored, 2 null value will be ignored

mergeArr: if mergeArr equal to true,

example

simple extend example

const target = {
  foo: {
    a: 1,
    b: 2
  }
}
const source = {
  foo: {
    b: 1,
    c: 1
  }
}

const output = pObj.extend(target, source)
// output = { foo: {a: 1, b: 1, c: 1}}

multiple extends example

const target = {
  foo: {
    a: 1,
    b: 2
  }
}
const source1 = {
  foo: {
    c: 1
  }
}
const source2 = {
  foo: {
    b: 3,
    e: 3
  }
}

const output = pObj.extend(target, [source1, soruce2])
// output = { foo: {a: 1, b: 3, c: 1, e: 3}}