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

  • Home
  • SEARCH
  • 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 8137921
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T11:19:53+00:00 2026-06-06T11:19:53+00:00

I have an enum in a file: goog.provide(‘animals.Fish’); animals.Fish = function(obj) { this.name_ =

  • 0

I have an enum in a file:

goog.provide('animals.Fish');

animals.Fish = function(obj) {
  this.name_ = obj[animals.Fish.Properties.NAME];
  this.awesomenessLevel_ = obj[animals.Fish.Properties.AWESOMENESS];
}

/**
 * Public list of properties.
 * @enum {string}
 */
animals.Fish.Properties = {
  NAME: 'name',
  AWESOMENESS: 'awesomenessLevel',
}

How come I can’t access this enum as a static field of Fish in another class like this?

goog.require('animals.Fish');
...
var tuna = new animals.Fish(
  animals.Fish.NAME: 'tuna',
  animals.Fish.AWESOMENESS: '100'
)
...
  • 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-06T11:19:54+00:00Added an answer on June 6, 2026 at 11:19 am

    Closure enumeration types are based on the concept of Enum Types from languages such as Java and C++. In Java, enum types are defined as follows:

    An enum type is a type whose fields consist of a fixed set of constants. Common examples include compass directions (values of NORTH, SOUTH, EAST, and WEST) and the days of the week.

    In your example above, animals.Fish.Properties should probably be represented as a record type, since the assigned values are not constants. In the example below, animals.Fish.Properties has been renamed animals.Properties so that it could be applied to any type of animal (not just fish).

    fish.js

    goog.provide('animals.Fish');
    goog.provide('animals.Properties');
    
    
    /** @typedef {{name: string, awesomeness: string}} */
    animals.Properties;
    
    
    /**
     * @param {animals.Properties} properties Animal properties.
     * @constructor 
     */
    animals.Fish = function(properties) {
      /** @type {string} */
      this.name_ = properties.name;
    
      /** @type {string} */
      this.awesomenessLevel_ = properties.awesomeness;
    };
    
    
    /**
     * @return {string} The name of the fish.
     */
    animals.Fish.prototype.getName = function() {
      return this.name_;
    };
    

    animals_app.js

    goog.provide('animals.app');
    
    goog.require('animals.Fish');
    
    animals.app.tuna = new animals.Fish({name: 'tuna', awesomeness: '100'});    
    alert(animals.app.tuna.getName()); // alerts 'tuna'
    

    On a side note, in the original example there should not be a comma after: AWESOMENESS: 'awesomenessLevel' in the definition of animals.Fish.Properties. In addition, in your second file you need to use the fully qualified enum name. So instead of animals.Fish.NAME it would be animals.Fish.Properties.NAME.

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

Sidebar

Related Questions

I have registered an enumeration type ClefType within my header file - this enum
gcc 4.1.2 c99 I have the following enum's in this file ccsmd.h : enum
I have defined a enum as below in the XSD file <xs:simpleType name=PaperSizes> <xs:restriction
I have an enum defined in the Constants.h file this way: typedef enum {
I have this enumeration: enum battleType {localEnemy,multiplayerEnemy}; Which is declared in the .h file
I have enum like this [Flags] public enum Key { None = 0, A
I have enum like this: public enum ObectTypes { TypeOne, TypeTwo, TypeThree, ... TypeTwenty
I have an enum class called Gender , and I have values in this
The original title was How to generate enum from properties file using ant? I
I have this enumeration public enum LightFiles { PNG, JPG, GIF, FLV, TIF, BMP,

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.