Enumerable properties


just want to say, sexy new forum :wink:

right to the point -

I am currently building something that needs to run through an objects properties and list all the keys.

currently if we take a point light as an example -

Object.keys(myPointLight).forEach(function(key) { // my code ere }

it gives me MOST properties, but something like position isnt made available but _position is?

now… I am a “newb” when it comes to coding as i am self taught, but as i understand, youre not supposed to directly edit variables beginning with _.

so the real question is, is there a reason variables like position arent enumerable and therefore wont appear as an object key in my foreach ?

EDIT: for those curious, i am using dat.gui to loop through and display properties for an object i have selected in my scene.

hope this makes sense!
many thanks

so ive sorted it myself (unless someone has a better idea) -

Object.keys(passedObject).forEach(function(initialKey) {
    let key = null;

    if(initialKey[0] === "_"){
        key = initialKey.replace(/[_]/g,"")
        key = initialKey;
    //do rest of the tings with key

I guess _position is the actual var but position is the setter hence why I am having this issue.

again if anyone has a better suggestion for me to fix this then please feel free :slight_smile:

You are doing it basically how I would do it.

Maybe add a test in there to make sure it is a value and not another object or function.

position should be a setter and getter, though I thought.

One sec I’m gonna check something this morning they weigh in again.

I do know you are not grabbing the values from the code you have posted, why are you grabbing these keys?

Update, so I am actually wondering why ‘position’ is not coming up because it is defined as a property as far as I know and even when you do something like this:


It does not come up, which it should… because this method would only hide it from the “keys” not
“defineProperty” method.

So I am actually kinda lost on why it does not come up! I bet it has to do with some fancy transcript compiler magic that I am not thinking of.

so i am doing this to create a list of properties using dat.gui.

which will allow me to displace the properties graphically for a user to manipulate a scene. hence why id prefer to use the correct variables and not the private ones