Browse Source

util: improve function signature of util._extend

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: https://github.com/nodejs/node/pull/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>
v6.x
Sakthipriyan Vairamani 8 years ago
committed by Jeremiah Senkpiel
parent
commit
d67ece2f68
  1. 2
      doc/api/util.md
  2. 12
      lib/util.js

2
doc/api/util.md

@ -812,7 +812,7 @@ deprecated: v0.11.3
Deprecated predecessor of `console.log`. Deprecated predecessor of `console.log`.
### util.\_extend(obj) ### util.\_extend(target, source)
<!-- YAML <!-- YAML
added: v0.7.5 added: v0.7.5
deprecated: v6.0.0 deprecated: v6.0.0

12
lib/util.js

@ -983,16 +983,16 @@ exports.inherits = function(ctor, superCtor) {
Object.setPrototypeOf(ctor.prototype, superCtor.prototype); Object.setPrototypeOf(ctor.prototype, superCtor.prototype);
}; };
exports._extend = function(origin, add) { exports._extend = function(target, source) {
// Don't do anything if add isn't an object // Don't do anything if source isn't an object
if (add === null || typeof add !== 'object') return origin; if (source === null || typeof source !== 'object') return target;
var keys = Object.keys(add); var keys = Object.keys(source);
var i = keys.length; var i = keys.length;
while (i--) { while (i--) {
origin[keys[i]] = add[keys[i]]; target[keys[i]] = source[keys[i]];
} }
return origin; return target;
}; };
function hasOwnProperty(obj, prop) { function hasOwnProperty(obj, prop) {

Loading…
Cancel
Save