Skip to content

Commit

Permalink
Add ol.Collection.extend
Browse files Browse the repository at this point in the history
  • Loading branch information
twpayne committed Mar 6, 2013
1 parent c9cce57 commit 23f0097
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/ol/collection.js
Expand Up @@ -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.
Expand Down
11 changes: 11 additions & 0 deletions test/spec/ol/collection.test.js
Expand Up @@ -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');
Expand Down

0 comments on commit 23f0097

Please sign in to comment.