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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T20:26:45+00:00 2026-06-17T20:26:45+00:00

I think I’m misunderstanding something here. I have an object that contains a property

  • 0

I think I’m misunderstanding something here. I have an object that contains a property that I wish to be non enumerable. I want to be able to assign values to it from within the object’s functions itself, but when I do so, the property becomes enumerable.

Example:

function ObjectNode() {
}

Object.defineProperty(ObjectNode.prototype, "parent", {
    value:null
    // enumerable and configurable default to false
}

// Pass an ObjectNode instance and set this object node as its parent
ObjectNode.prototype.addChild = function(node) {
    node.parent = this;    // <-- node.parent is now enumerable
    ...more code...
};

What actually happens is that assigning node.parent a value creates a new “own” property called parent, which overrides the original.

Is there a way I can internally assign a value to a non enumerable property without doing this? Or do I have to resort to getter/setter properties that reference a variable within a closure?

EDIT:

GGG deserves credit for answering this, because it was his advice that led me to my ultimate answer.

What I wanted to do was essentially hide a simple property from the ‘for(key in object)’ statement. I was able to do this as so:

function ObjectNode() {
    Object.defineProperty(this, "parent", {
        value:null, 
        writable:true
    });
}

One reason I balked at this to start with was the mistaken understanding that I did not want the property to be recreated with each instance. But, duh, that’s what an instance property is!!!

Thanks, GGG, for helping me realign my brain!

  • 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-17T20:26:46+00:00Added an answer on June 17, 2026 at 8:26 pm

    You have created a property of the prototype property which is non-configurable, but it can still be shadowed by properties of objects created by the constructor.

    function ObjectNode() {
    }
    
    Object.defineProperty(ObjectNode.prototype, "parent", {
        value: null,
        configurable: false
    })
    
    ObjectNode.prototype.addChild = function (node) {
        node.parent = this;    // <-- node.parent is now enumerable
    }
    
    var mom = new ObjectNode();
    var kid = new ObjectNode();
    
    mom.addChild(kid);
    
    console.log(kid.parent == mom);  // works, logs true
    
    kid.parent = "foo";
    
    console.log(kid.parent);  // works, logs "foo"
    
    ObjectNode.prototype.parent = "foo"; 
    
    console.log(ObjectNode.prototype.parent); // fails, logs null
    

    The thing to remember is that properties of an object are properties of that object only, not properties of other objects with that object in their prototype chain. Instead, try creating a non-configurable property of the new object in the constructor:

    function ObjectNode() {
        Object.defineProperty(this, "parent", {
            value: null,
            configurable: false
        })
    }
    

    Of course, this will prevent your addChild function from working, since the property is no longer configurable. You could consider defining the property in that function instead, but it will still be configurable until it is set with addChild.

    All in all, your best bet in general is to not worry about making things unconfigurable if it’s not absolutely critical (and I’m not sure of any case where it would be). The world has gotten along pretty well without that functionality for a long time. 😉

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

Sidebar

Related Questions

Think that I have many activities,and all I want is this: I have a
Think you have a variable that contains a string of text with spaces inbetween
Think I have domain.com that redirects into some.otherdomain.com . I don't want to show
Think I have an integer array like this: a[0]=60; a[1]=321; a[2]=5; now I want
I think I have a basic understanding of this, but am hoping that someone
Think that you have a content div whether the content of a website is
Think Design: I have many applications that share the same user database! Other tables
Think I have a service that play musics , Also I have an actvity
Think I have an activity with some layouts, I want to know is it
Think I'm missing something bleeding obvious here and would appreciate any help. Thanks in

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.