LeonS
LeonS

Reputation: 2714

Problem with eval and google closure compiler

I'm using google closure to compress my code but I have a problem with the following line of code:

        eval('this.find(\''+ element_to_append_the_controller+ '\').'+controller_to_load+'(options_for_controller)');

I have to use eval because the method (controller_to_load) I have to execute on the element is variable and depend on the params I get.

My Problem is that I have to pass an object to that method, so I'm doing that as an String representation of the variable name(options_for_controller), but closure will change that name and won't change the variable name in my eval string.

My solutions would be:

But how can I do one of them or is there another solution?

Thanks

Upvotes: 1

Views: 962

Answers (2)

Jim Blackler
Jim Blackler

Reputation: 23169

Some programmers use eval because they don't realise instead of writing eval('a.' + b) you can write a[b]

Try this instead of your eval()

this.find(element_to_append_the_controller.toString())[controller_to_load](options_for_controller);

Upvotes: 3

Jakub Hampl
Jakub Hampl

Reputation: 40533

this.find(element_to_append_the_controller.toString())[controller_to_load](options_for_controller)

AKA don't use eval.

Upvotes: 0

Related Questions