1

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:

  • getting the variable name dynamic as string
  • parsing object (with callback functions) to string
  • disable compressing for these line of codes

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

Thanks

2 Answers 2

3

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);
Sign up to request clarification or add additional context in comments.

1 Comment

thanks, your right, replaced all evals with this type of dynamic execution, awesome.
0
this.find(element_to_append_the_controller.toString())[controller_to_load](options_for_controller)

AKA don't use eval.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.