Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7918385
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T15:29:22+00:00 2026-06-03T15:29:22+00:00

I’m debugging and upgrading some legacy PHP and JavaScript code and I’ve found some

  • 0

I’m debugging and upgrading some legacy PHP and JavaScript code and I’ve found some eval() functions I cannot get rid of. Coming from desktop programming environment, with compiled languages such as C/C++ I’ve never used the eval() function in javascript mainly because I didn’t know of its existence. I’ve been googling a while and from all that I’ve read I understand that eval() evaluates a string as if it was legit javascript code and executes it. I’ve managed to get rid of eval() functions which were being used to access dynamic properties and decoding JSON objects, however there’s a fairly advanced (and obscure) class definition which uses eval() that I haven’t been able to defeat.

Sample code:

 function Ddl(N) {
   this.lyr = document.getElementById(N);
   this.obj = N+"DDL_Lyr";
   eval(this.obj+"=this");
   this.lyr.setAttribute("onchange", this.obj+".onChange();");
 }

This function is an object constructor. DDL objects are used in the web page as:

 ddl_name = new Ddl('id_of_select');
 ddl_name.onChange = event_function;

For all that I know, eval(this.obj + "=this") should be the same as this.obj = this; but then the onchange event function event_function is not fired. I haven’t been able to guess why using firebug. If I use this.obj = this I can see the value of this.obj changing from id_of_selectDDL_Lyr to a pointer to the DDL object itself so I can figure why setAttribute fails, but using the eval() function this.obj doesn’t look to reflect the changes as code is executed, it always remains as ‘id_of_selectDDL_Lyr’, however it’s doing something since if I comment it out the onchange event is not fired.

I suspect it may be related to local or global scope, since I’ve read that eval() calls are executed in a different scope, but I don’t know how to ckeck it nor I know how to replace eval() with normal javascript code.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T15:29:23+00:00Added an answer on June 3, 2026 at 3:29 pm

    I think this code is equivalent:

    function Ddl(N) {
       var self = this;
       this.lyr = document.getElementById(N);
       this.obj = N + "DDL_Lyr";
       window[this.obj] = this;
       this.lyr.onchange = function() {
           self.onChange();
       };
    }
    

    The eval is not saying this.obj = this, it’s creating a new global variable with the name “N + DDL_Lyr” (where N is variable).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text
I used javascript for loading a picture on my website depending on which small
this is what i have right now Drawing an RSS feed into the php,
I am reading a book about Javascript and jQuery and using one of the
I have this code to decode numeric html entities to the UTF8 equivalent character.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.