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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T12:53:10+00:00 2026-05-31T12:53:10+00:00

I’ve created a pretty simple prototype: <script type=text/javascript> Days = { sunday: 0, monday:

  • 0

I’ve created a pretty simple prototype:

<script type="text/javascript">
    Days = { "sunday": 0, "monday": 1, "tuesday": 3, "wednesday": 4,
        "thursday": 5, "friday": 6, "saturday": 7 };
    alert("Day Names Enumerator=" + Days.friday);
</script>

The result of execution is:

Day Names Enumerator=6

Once I moved the enum definition into another file

File1.js:

    Days = { "sunday": 0, "monday": 1, "tuesday": 3, "wednesday": 4,
        "thursday": 5, "friday": 6, "saturday": 7 };

File2.html

<script type="text/javascript" src="File1.js"></script>
<script type="text/javascript">
    alert("Day Names Enumerator=" + Days.friday);
</script>

I’ve received an error:

Uncaught ReferenceError: Days is not defined

Question1: what is a problem with this approach? I’ve seen a lot of recommendations regarding enums in JS, but nothing about using them from different files

In the very end, I would like my enum to be a part of the class described in File1:

function File1Class(){
    this.prototype.Days2 = { "sunday": 0, "monday": 1, "tuesday": 3, "wednesday": 4,
        "thursday": 5, "friday": 6, "saturday": 7 };
}

and use it like this:

<script type="text/javascript" src="File1.js"></script>
<script type="text/javascript">
    alert("Day Names Enumerator=" + File1Class.Days2.friday);
</script>

But I still received pretty similar error:

Uncaught TypeError: Cannot read property ‘friday’ or undefined

Question2: How to use enum defined inside of the class? Again, I’ve seen a lot of recommendations regarding enums and classes in JS, but nothing about using them both

Please advise, any feedback is welcome.

Thanks a lot in advance.

EDIT:

Why you guys don’t make answers? That would help for all (I believe, at least I will be able to vote and reward you somehow).

With regards to the 1st question: I’ve added ‘var’ declaration before the ‘Days’ and that allowed to access its values from another file.

Thanks a lot!

With regards to the 2nd one: it looks like I should move Days2 declaration out of the class constructor to make it executed. I did that: put it before class declaration, after… but still can’t even call it from the class itself:

File1Class.prototype.Days2 = { "sunday": 0, "monday": 1, "tuesday": 3, "wednesday": 4,
    "thursday": 5, "friday": 6, "saturday": 7 };
function File1Class(value) {
    this.value = value;
    alert(1);
    alert("<b>From class internals:</b> " + File1Class.prototype.Days2.friday + "<br />");

The error is still the same:

Uncaught TypeError: Cannot read property ‘friday’ or undefined

Please advise! Any ideas are welcome!

  • 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-31T12:53:11+00:00Added an answer on May 31, 2026 at 12:53 pm

    In “EDIT” section of the answer I’ve answered to the question 1, for consistency purpose it is:

    “var” should be used to define any global variable (thanks to Stoive and jfriend00 for the suggestion)

    With regards to the 2nd question: I had another syntax problem in my class file, once it was fixed the proper solution (again, suggested by Stoive) helped:

    declaration should not be put into constructor, it should be declared earlier to be executed.

    Many thanks to all!

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
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
I am reading a book about Javascript and jQuery and using one of the
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
Seemingly simple, but I cannot find anything relevant on the web. What is the
I am doing a simple coin flipping experiment for class that involves flipping a
I am trying to render a haml file in a javascript response like so:

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.