I want to run a loop that auto increase the function name by 1. For easier to understand:
My currently code:
for(var i = 1; i <= 2; i++) {
var fn = 'this.getExterior',
el = (fn + i + '()').getInnerItems();
}
I want to increase the function name and retrieve something like this.getExterior1 , this.getExterior2. The above code give me an object not a function. Can someone give me a solution how to achieve it. Thank you very much in advance!
You can’t really use strings as code (
evalcan but it’s not necessary here). You can use the[]syntax:(Also,
functionis a keyword; you cannot use it as a variable name.)