From: Alexander Ebert Date: Mon, 4 May 2015 12:09:01 +0000 (+0200) Subject: Added Dictionary.merge() X-Git-Tag: 3.0.0_Beta_1~2415 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=5f335673d5a29cd92748ce117758240430c24016;p=GitHub%2FWoltLab%2FWCF.git Added Dictionary.merge() --- 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)); + } } };