From 89191154393b09424e243adbe5f446f1666bd436 Mon Sep 17 00:00:00 2001 From: Dimitris Halatsis Date: Wed, 18 Mar 2020 18:52:35 +0200 Subject: [PATCH] Move List.prototype.toItem out of inner init (#1828) --- lib/list.js | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/lib/list.js b/lib/list.js index 4f4dfed7..94a2a953 100644 --- a/lib/list.js +++ b/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);