From cc37ad1ffc33223f02b2bfd6b8371ec2ba796d35 Mon Sep 17 00:00:00 2001 From: Benjamin Renard Date: Sun, 12 Jan 2014 20:08:27 +0100 Subject: [PATCH] Improve GroupsList each() method and use it in count() and export() methods --- inc/myco_objects.js | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/inc/myco_objects.js b/inc/myco_objects.js index 8ed0340..c05b51f 100644 --- a/inc/myco_objects.js +++ b/inc/myco_objects.js @@ -28,13 +28,9 @@ function GroupList() { } this.export=function() { - ret={}; - for (el in this) { - if (this.isGroup(this[el])) { - ret[el]=this[el].export(); - } - } - return ret; + return this.each(function(idx,group) { + return group.export(); + }); } this.import=function(groups) { @@ -60,18 +56,20 @@ function GroupList() { this.each=function(fct) { var idx=0; + var ret={}; for (el in this) { if(this.isGroup(this[el])) { - fct(idx++,this[el]); + ret[el]=fct(idx++,this[el]); } } + return ret; } this.count=function() { len=0; - for (el in this) { - if (this.isGroup(this[el])) len=len+1; - } + this.each(function(idx,group) { + len=len+1; + }); return len; }