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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T06:06:07+00:00 2026-05-31T06:06:07+00:00

I have an object declared like this: my.namespace.FEATURES = { FIRST_FEATURE = first feature,

  • 0

I have an object declared like this:

my.namespace.FEATURES = {
    FIRST_FEATURE = "first feature",
    SECOND_FEATURE = "second feature"
};

I use my.namespace.my.object to keep track of what kinds of features are available/implemented in my code. Every newly released version will have a modified set of features. A third-party using my minimized code will want to know what they can do in the version they have, so I supply the following function, which is exported, so that they know what they can do.

my.namespace.hasFeature = function(feature) {
    for(var prop in my.namespace.FEATURES) {
        if(my.namespace.FEATURES[prop] == feature) {
            return true;
        }
    }
    return false;
}

The problem is that the properties are getting renamed when I run Closure Compiler.

My question is: what’s the best way to keep those properties preserved? I know I can export the property, but it feels kind of dirty for some reason. Is there a Closure best practice to preserve the properties of an object?

  • 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-31T06:06:08+00:00Added an answer on May 31, 2026 at 6:06 am

    Exporting is there for a reason – as a directive to the Closure library that this is used by outside agents so it should not be renamed. The sections here on exporting explain how you can force Closure to keep a symbol intact (with no renaming). You mostly just need to follow the directions here. There is nothing “dirty” about exporting. It is there for exactly what you need – to tell Closure that this symbol is used by an external agent and cannot be renamed.

    The other trigger that can keep Closure from renaming a property is if it is accessed by a string like this:

    var f = "FIRST_FEATURE";
    my.namespace.FEATURES[f] = "first feature";
    

    In that case Closure sees that your code is using strings to address a property and (since it never messes with string values) it realizes that it can’t rename the FIRST_FEATURE property safely.

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

Sidebar

Related Questions

If I have a method declared like this: private void someFunction(object[] param1) When I
I have a declarative SQLAlchemy object with deferred columns, declared like this: class Review(Base):
I have two classes declared like this: class Object1 { protected ulong guid; protected
I have an object Foo that has an NSNumber property which is declared like
To keep the global namespace clean, my JavaScript code is wrapped like this: (function()
I have a plugin declared like this. (function ($) { var settings = {
Well, I have something like this: trait A class Serving(a: => A) object App
I have an Action delegate declared like this. private readonly Action<List<PSDPoint>[]> _psdAction; _psdAction =
I have three NSString properties declared like this: @property(nonatomic,retain) NSString *currentPassword; @property(nonatomic,retain) NSString *newPassword;
I have a c# object with a property called Gender which is declared as

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.