Make upgradeTo an object prototype
Change-Id: Ibdedbc5a57215151f97c5903ac69ba3ce6bab10c
diff --git a/dev/js/src/util.js b/dev/js/src/util.js
index 42edf44..e227c67 100644
--- a/dev/js/src/util.js
+++ b/dev/js/src/util.js
@@ -27,6 +27,20 @@
return this.toLowerCase().replace(_slug1RE, '').replace(_slug2RE, '-');
};
+/**
+ * Upgrade this object to another object,
+ * while private data stays intact.
+ *
+ * @param {Object} An object with properties.
+ */
+Object.prototype.upgradeTo = function (props) {
+ for (let prop in props) {
+ this[prop] = props[prop];
+ };
+ return this;
+};
+
+
// Add toggleClass method similar to jquery
HTMLElement.prototype.toggleClass = function (c1, c2) {
const cl = this.classList;
@@ -201,4 +215,4 @@
//filter by actually being direct child node
classElements = classElements.filter(subElement => subElement.parentNode === element);
return classElements;
-};
\ No newline at end of file
+};