I'm working on a javascript game for fun, where I have an array of character objects. I'm periodically doing checks on fields within the objects, (like characters[i].xpos, characters[i].ypos, and so on). Is it more efficient to add a function to the prototype of the class to handle moving left and right, and call that periodically, or more efficient to have a global function that adjusts the x and y pos of the character object?
Thanks for your help guys!
Edit: Thanks for your answers guys. I'll try to be more specific. I have one global update function that is called with an interval and has a bunch of code in it that changes the properties of an object, like:
globalupdate() {
characters[i].posx++;
characters[i].posy++;
... and more code like that
}
Would it be faster to just write a prototype function within that class and call that? Like:
globalupdate() {
characters[i].update();
}
Thanks for all the quick replies!