Skip to content

Commit

Permalink
Modernize Util.extend
Browse files Browse the repository at this point in the history
  • Loading branch information
otacke committed Dec 22, 2023
1 parent 85cf0db commit 58e50b6
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions src/scripts/services/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,26 @@
export default class Util {
/**
* Extend an array just like JQuery's extend.
* @param {...object} var_args Objects to be merged.
* @returns {object} Merged objects.
*/
static extend() {
for (let i = 1; i < arguments.length; i++) {
for (let key in arguments[i]) {
if (Object.prototype.hasOwnProperty.call(arguments[i], key)) {
static extend(var_args) {
for (let i = 1; i < var_args.length; i++) {
for (let key in var_args[i]) {
if (Object.prototype.hasOwnProperty.call(var_args[i], key)) {
if (
typeof arguments[0][key] === 'object' &&
typeof arguments[i][key] === 'object'
typeof var_args[0][key] === 'object' &&
typeof var_args[i][key] === 'object'
) {
this.extend(arguments[0][key], arguments[i][key]);
this.extend(var_args[0][key], var_args[i][key]);
}
else {
arguments[0][key] = arguments[i][key];
var_args[0][key] = var_args[i][key];
}
}
}
}
return arguments[0];
return var_args[0];
}

/**
Expand Down Expand Up @@ -137,7 +138,7 @@ export default class Util {
*/
static callOnceVisible(dom, callback) {
if (typeof dom !== 'object' || typeof callback !== 'function') {
return; // Invalid arguments
return; // Invalid var_args
}

// iOS is behind ... Again ...
Expand Down

0 comments on commit 58e50b6

Please sign in to comment.