Move List.prototype.toItem out of inner init (#1828)

This commit is contained in:
Dimitris Halatsis 2020-03-18 18:52:35 +02:00 committed by GitHub
parent df394a613b
commit 8919115439
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 15 additions and 15 deletions

View File

@ -68,21 +68,6 @@ function List(items, itemType, parent) {
});
}
List.prototype.toItem = function(item) {
if (isClass(this.itemType)) {
return new this.itemType(item);
} else {
if (Array.isArray(item)) {
return item;
} else if (this.itemType === Date) {
if (item === null) return null;
return new Date(item);
} else {
return this.itemType(item);
}
}
};
items.forEach(function(item, i) {
if (itemType && !(item instanceof itemType)) {
arr[i] = arr.toItem(item);
@ -98,6 +83,21 @@ util.inherits(List, Array);
const _push = List.prototype.push;
List.prototype.toItem = function(item) {
if (isClass(this.itemType)) {
return new this.itemType(item);
} else {
if (Array.isArray(item)) {
return item;
} else if (this.itemType === Date) {
if (item === null) return null;
return new Date(item);
} else {
return this.itemType(item);
}
}
};
List.prototype.push = function(obj) {
const item = this.itemType && (obj instanceof this.itemType) ? obj : this.toItem(obj);
_push.call(this, item);