Skip to content

Commit 5ded216

Browse files
freitagbrnfischer
authored andcommitted
Use Object.assign if possible (shelljs#593)
* Fix typo * Set objectAssign to Object.assign if defined * Use correct terminology
1 parent e4b71f0 commit 5ded216

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

src/common.js

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -251,19 +251,21 @@ function randomFileName() {
251251
exports.randomFileName = randomFileName;
252252

253253
// objectAssign(target_obj, source_obj1 [, source_obj2 ...])
254-
// Ponyfill for Object.assign
254+
// "Ponyfill" for Object.assign
255255
// objectAssign({A:1}, {b:2}, {c:3}) returns {A:1, b:2, c:3}
256-
function objectAssign(target) {
257-
var sources = [].slice.call(arguments, 1);
258-
sources.forEach(function (source) {
259-
Object.keys(source).forEach(function (key) {
260-
target[key] = source[key];
256+
var objectAssign = typeof Object.assign === 'function' ?
257+
Object.assign :
258+
function objectAssign(target) {
259+
var sources = [].slice.call(arguments, 1);
260+
sources.forEach(function (source) {
261+
Object.keys(source).forEach(function (key) {
262+
target[key] = source[key];
263+
});
261264
});
262-
});
263265

264-
return target;
265-
}
266-
exports.extend = Object.assign || objectAssign;
266+
return target;
267+
};
268+
exports.extend = objectAssign;
267269

268270
// Common wrapper for all Unix-like commands that performs glob expansion,
269271
// command-logging, and other nice things

0 commit comments

Comments
 (0)