瀏覽代碼

Use spread syntax

https://caniuse.com/mdn-javascript_operators_spread
Simon Legner 1 年之前
父節點
當前提交
ff7a10c003

+ 2 - 1
assets/javascripts/app/app.js

@@ -87,7 +87,8 @@ class App extends Events {
           },
           dataCallback(data) {
             try {
-              $.extend(data.user || (data.user = {}), app.settings.dump());
+              data.user ||= {};
+              Object.assign(data.user, app.settings.dump());
               if (data.user.docs) {
                 data.user.docs = data.user.docs.split("/");
               }

+ 3 - 3
assets/javascripts/app/searcher.js

@@ -185,7 +185,7 @@ app.Searcher = class Searcher extends Events {
 
   constructor(options) {
     super();
-    this.options = $.extend({}, Searcher.DEFAULTS, options || {});
+    this.options = { ...Searcher.DEFAULTS, ...(options || {}) };
   }
 
   find(data, attr, q) {
@@ -332,7 +332,7 @@ app.Searcher = class Searcher extends Events {
     for (let j = this.scoreMap.length - 1; j >= 0; j--) {
       var objects = this.scoreMap[j];
       if (objects) {
-        results.push.apply(results, objects);
+        results.push(...objects);
       }
     }
     return results.slice(0, this.options.max_results);
@@ -369,7 +369,7 @@ app.SynchronousSearcher = class SynchronousSearcher extends app.Searcher {
       if (!this.allResults) {
         this.allResults = [];
       }
-      this.allResults.push.apply(this.allResults, this.getResults());
+      this.allResults.push(...this.getResults());
     }
     return super.match(...arguments);
   }

+ 1 - 16
assets/javascripts/lib/util.js

@@ -421,18 +421,6 @@ $.smoothScroll = function (el, end) {
 // Utilities
 //
 
-$.extend = function (target, ...objects) {
-  for (var object of objects) {
-    if (object) {
-      for (var key in object) {
-        var value = object[key];
-        target[key] = value;
-      }
-    }
-  }
-  return target;
-};
-
 $.makeArray = function (object) {
   if (Array.isArray(object)) {
     return object;
@@ -573,10 +561,7 @@ const HIGHLIGHT_DEFAULTS = {
 };
 
 $.highlight = function (el, options) {
-  if (options == null) {
-    options = {};
-  }
-  options = $.extend({}, HIGHLIGHT_DEFAULTS, options);
+  options = { ...HIGHLIGHT_DEFAULTS, ...(options || {}) };
   el.classList.add(options.className);
   setTimeout(() => el.classList.remove(options.className), options.delay);
 };

+ 1 - 1
assets/javascripts/views/misc/notif.js

@@ -10,7 +10,7 @@ app.views.Notif = class Notif extends app.View {
   constructor(type, options) {
     super();
     this.type = type;
-    this.options = $.extend({}, this.constructor.defaultOptions, options || {});
+    this.options = { ...this.constructor.defaultOptions, ...(options || {}) };
     this.init0(); // needs this.options
     this.refreshElements();
   }