Skip to content

Commit b3e7ac2

Browse files
committed
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: #8187 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: Yorkie Liu <[email protected]> Reviewed-By: Brian White <[email protected]>
1 parent 02ed21a commit b3e7ac2

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

doc/api/util.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -812,7 +812,7 @@ deprecated: v0.11.3
812812
813813
Deprecated predecessor of `console.log`.
814814

815-
### util.\_extend(obj)
815+
### util.\_extend(target, source)
816816
<!-- YAML
817817
added: v0.7.5
818818
deprecated: v6.0.0

lib/util.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -983,16 +983,16 @@ exports.inherits = function(ctor, superCtor) {
983983
Object.setPrototypeOf(ctor.prototype, superCtor.prototype);
984984
};
985985

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

990-
var keys = Object.keys(add);
990+
var keys = Object.keys(source);
991991
var i = keys.length;
992992
while (i--) {
993-
origin[keys[i]] = add[keys[i]];
993+
target[keys[i]] = source[keys[i]];
994994
}
995-
return origin;
995+
return target;
996996
};
997997

998998
function hasOwnProperty(obj, prop) {

0 commit comments

Comments
 (0)