From 5f335673d5a29cd92748ce117758240430c24016 Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Mon, 4 May 2015 14:09:01 +0200 Subject: [PATCH] Added Dictionary.merge() --- .../files/js/WoltLab/WCF/Dictionary.js | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/wcfsetup/install/files/js/WoltLab/WCF/Dictionary.js b/wcfsetup/install/files/js/WoltLab/WCF/Dictionary.js index 8c0f0784a8..bbd01e22c8 100644 --- a/wcfsetup/install/files/js/WoltLab/WCF/Dictionary.js +++ b/wcfsetup/install/files/js/WoltLab/WCF/Dictionary.js @@ -89,9 +89,27 @@ define(function() { else { var keys = Object.keys(this._dictionary); for (var i = 0, length = keys.length; i < length; i++) { - callback(this._dictionary[keys[i]]); + callback(this._dictionary[keys[i]], keys[i]); } } + }, + + /** + * Merges one or more Dictionary instances into this one. + * + * @param {...Dictionary} var_args one or more Dictionary instances + */ + merge: function() { + for (var i = 0, length = arguments.length; i < length; i++) { + var dictionary = arguments[i]; + if (!(dictionary instanceof Dictionary)) { + throw new TypeError("Expected an object of type Dictionary, but argument " + i + " is not."); + } + + dictionary.forEach((function(value, key) { + this.set(key, value); + }).bind(this)); + } } }; -- 2.20.1