Added Dictionary.merge()
authorAlexander Ebert <ebert@woltlab.com>
Mon, 4 May 2015 12:09:01 +0000 (14:09 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Mon, 4 May 2015 12:09:01 +0000 (14:09 +0200)
wcfsetup/install/files/js/WoltLab/WCF/Dictionary.js

index 8c0f0784a8420bff9412a495b4d51c64decfc476..bbd01e22c8130e0634576da891032a5b64c0401b 100644 (file)
@@ -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));
+                       }
                }
        };