From 076141ad80708df685a936fecd0f109ab8e63836 Mon Sep 17 00:00:00 2001 From: bellord13 Date: Mon, 11 Oct 2021 11:14:25 +0300 Subject: [PATCH] fix --- assets/collection/collection.js | 30 ++++++++++++++++-------------- tests/kit.Collection.php | 2 -- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/assets/collection/collection.js b/assets/collection/collection.js index a59d5cb..04670ae 100644 --- a/assets/collection/collection.js +++ b/assets/collection/collection.js @@ -19,15 +19,15 @@ kit.PluginManager.register('Collection', function(module, exports, require, glob function setLastIndex(key){ var n = Number(key); - if (support.arr.isKey(key) && n > this.lastIndex) { - this.lastIndex = n; + if (support.arr.isKey(key) && n > this.__lastIndex) { + this.__lastIndex = n; } - return this.lastIndex; + return this.__lastIndex; } function actualParams() { var index; this.length = this.__keys.length; - this.lastIndex = 0; + this.__lastIndex = 0; for(index in this.__keys) { setLastIndex.call(this, this.__keys[index]); } @@ -39,21 +39,21 @@ kit.PluginManager.register('Collection', function(module, exports, require, glob var Collection = function (data = []) { this.data = data; if(Array.isArray(data)) { - this.type = 'array'; + this.__type = 'array'; } else if(typeof data === 'object') { - this.type = 'object'; + this.__type = 'object'; if(data.hasOwnProperty('length') && !Object.keys(data).includes('length')) { - this.type = 'arrayObject'; + this.__type = 'arrayObject'; } } else { - this.type = 'array'; + this.__type = 'array'; this.data = [data]; console.warn('collection: not support data' + typeof data); } var key; - this.lastIndex = 0; + this.__lastIndex = 0; this.length = 0; this.__keys = []; this.__values = []; @@ -66,7 +66,7 @@ kit.PluginManager.register('Collection', function(module, exports, require, glob }; Collection.prototype.all = function () { - if(this.type === 'array' || this.type === 'arrayObject') { + if(this.__type === 'array' || this.__type === 'arrayObject') { return this.toArray(); } return this.toObject(); @@ -115,7 +115,7 @@ kit.PluginManager.register('Collection', function(module, exports, require, glob * @return {kit.Collection} */ Collection.prototype.push = function (value) { - this.set(this.lastIndex + 1, value); + this.set(this.__lastIndex + 1, value); return this; }; Collection.prototype.get = function (key, defValue = undefined) { @@ -136,7 +136,7 @@ kit.PluginManager.register('Collection', function(module, exports, require, glob * @return {kit.Collection} */ Collection.prototype.map = function (callback) { - var res = getSimilarInstance(this.type); + var res = getSimilarInstance(this.__type); for (var key of Object.keys(this.data)) { res.put(key, valueEx(callback, this.data[key], key, this.data)); } @@ -185,7 +185,7 @@ kit.PluginManager.register('Collection', function(module, exports, require, glob * @return {kit.Collection} */ Collection.prototype.filter = function (callback = filter) { - var res = getSimilarInstance(this.type); + var res = getSimilarInstance(this.__type); this.each(function (value, key, arr) { if(valueEx(callback, value, key, arr)) { res.put(key, value); @@ -322,7 +322,9 @@ kit.PluginManager.register('Collection', function(module, exports, require, glob console.log('Collection', this.data); return this; }; - + /** + * @return {kit.Collection} + */ Collection.prototype.dd = function () { this.dump(); debugger; diff --git a/tests/kit.Collection.php b/tests/kit.Collection.php index bc8ff2c..5843061 100644 --- a/tests/kit.Collection.php +++ b/tests/kit.Collection.php @@ -179,8 +179,6 @@ kit.ready(['collection'], function () { - - });