Skip to content

Commit

Permalink
Merge pull request #911 from /issues/910@v2
Browse files Browse the repository at this point in the history
objects: extend fails in case of target=null (close #910)
  • Loading branch information
dfilatov committed Mar 12, 2015
2 parents 2fe510b + 408fff2 commit 4090469
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
5 changes: 5 additions & 0 deletions common.blocks/objects/objects.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ describe('objects', function() {
.should.be.eql({ p1 : 'v1' });
});

it('should return new object if target is null', function() {
objects.extend(null, { p1 : 'v1' })
.should.be.eql({ p1 : 'v1' });
});

it('should properly extend object with "hasOwnProperty" property', function() {
objects.extend(
{ hasOwnProperty : '' },
Expand Down
2 changes: 1 addition & 1 deletion common.blocks/objects/objects.vanilla.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ provide(/** @exports */{
* @returns {Object}
*/
extend : function(target, source) {
typeof target !== 'object' && (target = {});
(typeof target !== 'object' || target === null) && (target = {});

for(var i = 1, len = arguments.length; i < len; i++) {
var obj = arguments[i];
Expand Down

0 comments on commit 4090469

Please sign in to comment.