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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T05:08:02+00:00 2026-05-19T05:08:02+00:00

From a previous question , I have the following: So I have implemented a

  • 0

From a previous question, I have the following:

So I have implemented a resource class, now I’d like to continue extending it and add all my constants and enums (or as far as JS will allow…).

This is what I currently have:

var resources = {
  // images
  player  : new c_resource("res/player.png"),
  enemies : new c_resource("res/enemies.png"),
  tilemap : new c_resource("res/tilemap.png")
};

And this is what I would like to continue to extend it to:

var resources = {
  // images
  player  : new c_resource("res/player.png"),
  enemies : new c_resource("res/enemies.png"),
  tilemap : new c_resource("res/tilemap.png"),

  // enums
  directions : {up:0, right:1, down:2, left:3},
  speeds     : {slow: 1, medium: 3, fast: 5}
};

...

function enemies() {
  this.dir = resources.directions.down; // initialize to down
}

When I attempt to access resources.directions.up, my JS script goes down in a flaming pile of burning code. Are enums allowed in this context, and if not, how can I properly insert them to be used outside of a normal function? I have also tried defining them as global to a similar effect.


edits: fixed the comma…that was just an error in transcribing it.

When I run it in Firefox and watch the console, I get an error that says resources is undefined.

The resources ‘class’ is defined at the top of my script, and function enemies() directly follows…so from what I understand it should still be in scope…

  • 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-05-19T05:08:03+00:00Added an answer on May 19, 2026 at 5:08 am

    What’s the call stack to enemies? You could have done something like this:

    var foo = {
      bar: 1,
      f_rv: f()
    };
    
    function f() {
      return foo.bar;
    }
    

    which works halfway since you can declare functions “below” the code that uses them, but fails later since f() attempts to use foo, which is not constructed at the moment.

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

Sidebar

Related Questions

Following on from my previous question [link text][1] , I have a new problem.
This is a continuation question from a previous question I have asked I now
From a previous question I have seen that the CLR has workstation and server
Continuing from my previous question , is there a comprehensive document that lists all
Following on from my previous question , is it possible to make a Python
I have inherited a application framework from the previous developer where I now work.
From a previous question , I learn that Linq to SQL is not able
OK, this kind of follows on from my previous question . What I would
This came up from this answer to a previous question of mine . Is
Leading on from my previous questions I am going to try and clarify one

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.