Skip to content

Commit

Permalink
util: improve function signature of util._extend
Browse files Browse the repository at this point in the history
The function signature of `util._extend` is not intuitive and the
documentation doesn't specify the necessary second parameter. This
patch changes the parameter names in the code and the function params
in doc.

PR-URL: #8187
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Michaël Zasso <mic.besace@gmail.com>
Reviewed-By: Yorkie Liu <yorkiefixer@gmail.com>
Reviewed-By: Brian White <mscdex@mscdex.net>
  • Loading branch information
thefourtheye committed Aug 26, 2016
1 parent 02ed21a commit b3e7ac2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion doc/api/util.md
Original file line number Diff line number Diff line change
Expand Up @@ -812,7 +812,7 @@ deprecated: v0.11.3
Deprecated predecessor of `console.log`.

### util.\_extend(obj)
### util.\_extend(target, source)
<!-- YAML
added: v0.7.5
deprecated: v6.0.0
Expand Down
12 changes: 6 additions & 6 deletions lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -983,16 +983,16 @@ exports.inherits = function(ctor, superCtor) {
Object.setPrototypeOf(ctor.prototype, superCtor.prototype);
};

exports._extend = function(origin, add) {
// Don't do anything if add isn't an object
if (add === null || typeof add !== 'object') return origin;
exports._extend = function(target, source) {
// Don't do anything if source isn't an object
if (source === null || typeof source !== 'object') return target;

var keys = Object.keys(add);
var keys = Object.keys(source);
var i = keys.length;
while (i--) {
origin[keys[i]] = add[keys[i]];
target[keys[i]] = source[keys[i]];
}
return origin;
return target;
};

function hasOwnProperty(obj, prop) {
Expand Down

0 comments on commit b3e7ac2

Please sign in to comment.