Merely stating that "id
is undefined" doesn't automatically indicate that Object.defineProperty
had no effect, although I acknowledge that you examined the properties of this
immediately after calling Object.defineProperty
, which is puzzling. If GeometryIdCount()
returns undefined, then it makes sense why the value is undefined
later on. Have you confirmed that the property itself is truly undefined rather than just its value upon the constructor's completion?
It might be akin to using "utilize" instead of "use," or possibly it is required by Typescript, ES6, or three.js, but why not consider writing this instead:
this.id = GeometryIdCount();
This will still assign an unknown value to this.id
if the function returns undefined.
Update:
Your query prompted me to delve into the specifics of what Object.defineProperty entails, and the findings were both surprising and enlightening. When working with WebGL, I personally did not utilize three.js, so I mistakenly assumed that Geometry was a custom function created by you.
By calling Object.defineProperty as described (using an object with only the "value" property for the 3rd argument), it effectively sets the writable, configurable, and enumerable properties – all of which are inherent to Object properties – to false. Conversely, this.id = GeometryIdCount()
would set these 3 properties to true. The creator of three.js seemingly intended to allocate a unique key to each Geometry object while safeguarding against any alterations by users. Other reasons were not explored by myself.
I suggest making a duplicate of your project, removing any sensitive information (if planning to share here), and eliminating extraneous code where possible to pinpoint the root cause of the issue. Try refraining from removing code once the problematic behavior – like the absence or undefined state of the id property – can no longer be replicated. I conducted tests in a simplified program, attempting to recreate the problem by performing actions like
Geometry.prototype.id = undefined
prior to invoking var
g = Geometry(...)
without utilizing the new keyword, yet could not reproduce the anomaly. Intrusive measures such as altering the behavior of
GeometryIdCount
or obstructing the creation of the
id
property were not pursued, as they appear deliberate acts of sabotage that I presume are not suspected in your scenario.