Merge pull request #1799 from jeznag/fix-issue-with-new-array
Fix issue with broken compatibility with array constructor
This commit is contained in:
commit
002137dd5d
|
@ -27,6 +27,11 @@ function List(items, itemType, parent) {
|
|||
}
|
||||
}
|
||||
|
||||
if (typeof items === 'number') {
|
||||
// trying to initialise empty array with a length
|
||||
items = [...new Array(items)];
|
||||
}
|
||||
|
||||
const arr = [];
|
||||
arr.__proto__ = List.prototype;
|
||||
|
||||
|
|
|
@ -38,6 +38,16 @@ function PhoneCtor(label, num) {
|
|||
this.num = num;
|
||||
}
|
||||
|
||||
describe('Does not break default Array functionality', function() {
|
||||
it('allows creating an empty length with a specified length', function() {
|
||||
const list = new List(4);
|
||||
list.should.be.an.instanceOf(Array);
|
||||
list.length.should.be.eql(4);
|
||||
should.not.exist(list.itemType);
|
||||
list.toJSON().should.eql([undefined, undefined, undefined, undefined]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('list of items typed by a class', function() {
|
||||
it('allows itemType to be a class', function() {
|
||||
const phones = givenPhones();
|
||||
|
|
Loading…
Reference in New Issue