Move List.prototype.toItem out of inner init (#1828)
This commit is contained in:
parent
df394a613b
commit
8919115439
30
lib/list.js
30
lib/list.js
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue