From 23f00975173fbce2e2f9f49d8d23988bc807990c Mon Sep 17 00:00:00 2001 From: Tom Payne Date: Wed, 6 Mar 2013 13:18:34 +0100 Subject: [PATCH] Add ol.Collection.extend --- src/ol/collection.js | 11 +++++++++++ test/spec/ol/collection.test.js | 11 +++++++++++ 2 files changed, 22 insertions(+) diff --git a/src/ol/collection.js b/src/ol/collection.js index 86c331302f..f8cf78ddab 100644 --- a/src/ol/collection.js +++ b/src/ol/collection.js @@ -99,6 +99,17 @@ ol.Collection.prototype.clear = function() { }; +/** + * @param {Array} arr Array. + */ +ol.Collection.prototype.extend = function(arr) { + var i; + for (i = 0; i < arr.length; ++i) { + this.push(arr[i]); + } +}; + + /** * @param {Function} f Function. * @param {Object=} opt_obj Object. diff --git a/test/spec/ol/collection.test.js b/test/spec/ol/collection.test.js index a5923b540d..81ef412fbb 100644 --- a/test/spec/ol/collection.test.js +++ b/test/spec/ol/collection.test.js @@ -235,6 +235,17 @@ describe('ol.collection', function() { }); }); }); + + describe('extending a collection', function() { + it('adds elements to end of the collection', function() { + collection.extend([1, 2]); + expect(collection.getLength()).toEqual(2); + expect(goog.array.equals(collection.getArray(), [1, 2])).toBeTruthy(); + expect(collection.getAt(0)).toEqual(1); + expect(collection.getAt(1)).toEqual(2); + }); + }); + }); goog.require('goog.array');