sawa
sawa

Reputation: 168199

Executing a command given in string

Having the function name 'foo' and its argument 'arg' in strings, is there a way to execute foo(arg)? Do I need to use eval? I want to do something like send(foo, arg) if it were in Ruby.

Upvotes: 2

Views: 54

Answers (1)

SLaks
SLaks

Reputation: 887777

You can use indexer notation:

window[name](arg);

Upvotes: 4

Related Questions