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>
This commit is contained in:
parent
02ed21aa5c
commit
b3e7ac2605
@ -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
|
||||
|
12
lib/util.js
12
lib/util.js
@ -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) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user