How to do a "each" method in JS

So hi guys,


I was wondering because I want to do something like a atb system similar to this : 


vLIFfmt.png



the problem in Ruby it's easy...but in JS it's kinda weird...I just don't know how to do a proper "each" method.


here my coding...in simple this really similar to game_Battler I just don't know how to initialize it

Spoiler
var NioPlugin = NioPlugin || {};
var NioPlugin.ATB_GUI = NioPlugin.ATB_GUI || {};


//==============================================================================
// ■ Sprite_ATB
//------------------------------------------------------------------------------
// The Sprite class who handle
//==============================================================================
function Sprite_ATB(){this.initialize.apply(this,arguments);}
Sprite_ATB.prototype.constructor = Sprite_ATB;

Sprite_ATB.prototype = Object.create(Sprite_Base.prototype);

Sprite_ATB.prototype.initialize = function(battler) {
Sprite_Base.prototype.initialize.call(this);
this.initMember();
this.setBattler(battler);
};

Sprite_ATB.prototype.initMember = function() {
this.anchor.x = 0.5;
this.anchor.y = 1;
this._homeX = 0;
this._homeY = 0;
this._finalX = 0;
this._finaly = 0;
this._battler = null;

};

Sprite_ATB.prototype.setBattler = function(battler) {
this._battler = battler;
};

Sprite_ATB.prototype.update = function() {
Sprite_Base.prototype.update.call(this);
while(ImageManager.isReady() != true){
this.loadBitmap();
}
if(this._battler && ImageManager.isReady()){
this.updateVisibility();
this.bitmap = ImageManager.loadSystem("ATB_" + this._battler.name());
} else {
this.bitmap = ImageManager.loadSystem("");
}
};
//===============================================================================
// => END : Sprite_ATB
//===============================================================================

//==============================================================================
// ■ Spriteset_Battle
//------------------------------------------------------------------------------
// The set of sprites on the battle screen.
//==============================================================================

NioPlugin.ATB_GUI.createUpperLayer = Spriteset_Battle.prototype.createUpperLayer;
Spriteset_Battle.prototype.createUpperLayer = function(){
NioPlugin.ATB_GUI.createUpperLayer.call(this);
this.createATBLayout();
this.createATBFace();
};

Spriteset_Battle.prototype.createATBLayout = function() {
this._layout = new Sprite();
this._layout.bitmap = ImageManager.loadSystem("atbLayout");
this._layout.x = 100;
this._layout.y = 100;
this.addChild(this._layout);
};

Spriteset_Battle.prototype.createATBFace = function() {
this.createEnemieFaces();
this.createActorFaces();
};

Spriteset_Battle.prototype.createEnemieFaces = function() {};

// create the ATB actorFace for the atb bar
Spriteset_Battle.prototype.createActorFaces = function() {
this._atbActor = [];
for (var i = 0; i < this._atbActor.length; i++) {
this._atbActor = new Sprite_ATB(i);
this._battleField.addChild(this._atbActor);
};
};

// from a exemple I am unsure if this could work actually
for (var i = $gameParty.members().length - 1; i >= 0; i--) {
var actor = $gameParty.members();
}






thanks for any further answer
Unless you have to, don't iterate in reverse. Most JS engines expect you to iterate forwards, so they will optimize for this case. I would use one of those alternatives:


var members = $gameParty.members(), actor;
for(var i = 0, max = members.length; i < max; ++i) {
actor = members;
}

// or

var members = $gameParty.members();
for(var i = 0, actor; actor = members[i++]; ) {

}


Though the second version assumes, that all values are non-falsy, because it will break as soon as "actor" is assigned a falsy value (for example undefined, which is the intended way for this to break).


Both of those examples cache values and declare variables outside the loop. This is because the performance cost for reading a variable increases with its scope. $gameParty is a global variables and as such one of the most cost intensive to read. Also, creating a variable costs performance (although less than it would to read $gameParty during every iteration), which is why you should not do this inside a loop.


If you really want to loop in reverse, do it like this:


var members = $gameParty.members(), actor;
for(var i = members.length; i--; ) {
actor = members;
}


This has the added benefit, that you could remove the current actor from "members", without causing the loop to break, because its index isn't relevant in subsequent iterations.
actually this half help me..and half not helping me...actually I am not that dumb for not know how work a for loop ect


the problem is how do I initialize ...my class using this loop

Original thread: https://forums.rpgmakerweb.com/threads/how-to-do-a-each-method-in-js.56162/