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 7761969
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T14:16:16+00:00 2026-06-01T14:16:16+00:00

I want to improve a small framework, and therefore I want to get rid

  • 0

I want to improve a small framework, and therefore I want to get rid of two calls to eval.

Let the code speak:

# irf.coffee (The Framework)
# Classes which are appended to the namespace 'IRF'
classes = [
  "Background"
  "BoundingBox"
  # ...
]

# Namespace where to attach classes
@IRF = {}

# TODO: Get rid of eval(c)
for c in classes
  @IRF[c] = eval(c)

I only want the IRF to ‘pollute’ the global namespace so I could access classes/objects like new IRF.Background().

The goal of this framework is to be used by other projects including this framework.
So I might have a project like this:

class TowerMap extends IRF.Game
  constructor: (width, height) ->
    @background = new IRF.Background(width, height)

As you see, I have to use the IRF namespace here, but within this particular project I’d like to use it without the namespace, as I did this:

# Require all Class of IRF, so we won't need namespace here
# TODO: get rid of eval
eval("var #{k} = v") for k,v of IRF

class TowerMap extends Game
  constructor: (width, height) ->
    @background = new Background(width, height)

Everything works as expected, but somehow those two evals disturb me.
Might there be another solution?

  • 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-01T14:16:17+00:00Added an answer on June 1, 2026 at 2:16 pm

    Why not just import the bits you need?

    Background = IRF.Background
    
    class TowerMap extends Game
      constructor: (width, height) ->
        @background = new Background(width, height)
    

    You should be aware that eval in EcmaScript 5 strict mode can’t introduce new variable declarations so eval('var x = ...') in strict mode will not make a variable that is visible to surrounding non-eval code.

    EcmaScript 5 Appendix C says

    Strict mode eval code cannot instantiate variables or functions in the variable environment of the caller to eval. Instead, a new variable environment is created and that environment is used for declaration binding instantiation for the eval code (10.4.2).

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

Sidebar

Related Questions

I got some code and I want improve it to find and replace bytes
I work on the JBJF Project on SourceForge and we want to improve on
This is my first post in stackoverflow. I want to improve its google pagerank
I am working on image processing library in c#. want to improve performance/speed and
I am teaching programming to my nephews and I want them to improve their
To improve performance of our MVC3 application we want to mark some Controller's to
I want to get better at vectorizing my loops in MATLAB. At the moment,
I want to encrypt/decrypt lots of small (2-10kB) pieces of data. The performance is
I want to improve the cross platform behavior of a java application. However, its
I want to improve my coding skills, so I have planned write a Mobile

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.