How to call dynamically-named method in Javascript

Have you ever created methods with generated names within a loop?

Here's how to call that dynamic functions.

The following code would behave like first_part_other_part( arguments );

var method_name = "first_part_";
var other_method_name = "other_part";

window[method_name + other_method_name]( arguments );

About Rick

Senior Front-end Software Engineer from Barcelona, Haidong Gumdo Instructor (korean martial art of the sword), street photographer, travel lover, TV addict, Boston Red Sox fan, and privacy advocate.

Leave a Reply

Add <code> Some Code </code> by using this tags.

*
*