Skip to content

Commit

Permalink
Merge 4826a61 into 5665d8a
Browse files Browse the repository at this point in the history
  • Loading branch information
SukkaW committed Dec 30, 2019
2 parents 5665d8a + 4826a61 commit ac6bdad
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 10 deletions.
16 changes: 11 additions & 5 deletions README.md
Expand Up @@ -2079,11 +2079,17 @@ The method is used to copy the values of all enumerable own and inherited proper

//Or using a function
const extend = (target, ...sources) => {
let source = [];
sources.forEach(src => {
source = source.concat([src, Object.getPrototypeOf(src)])
})
return Object.assign(target, ...source)
const length = sources.length;

if (length < 1 || target == null) return target;
for (let i = 0; i < length; i++) {
const source = sources[i];

for (const key in source) {
target[key] = source[key];
}
}
return target;
};
console.log(extend({}, new Foo, new Bar));
// output: { 'c': 3, 'd': 4, 'e': 5, 'f': 6 }
Expand Down
17 changes: 12 additions & 5 deletions tests/unit/all.js
Expand Up @@ -148,12 +148,19 @@ describe('code snippet example', () => {
}
Foo.prototype.d = 4;
Bar.prototype.f = 6;

const extend = (target, ...sources) => {
let source = [];
sources.forEach(src => {
source = source.concat([src, Object.getPrototypeOf(src)])
})
return Object.assign(target, ...source)
const length = sources.length;

if (length < 1 || target == null) return target;
for (let i = 0; i < length; i++) {
const source = sources[i];

for (const key in source) {
target[key] = source[key];
}
}
return target;
};

it("_.extend({}, new Foo, new Bar);", () => {
Expand Down

0 comments on commit ac6bdad

Please sign in to comment.