Wednesday, 13 September 2023

How to implement object internal slot property

I recognize that some Javascript Objects has some internal slot property surrounding with double square bracket [[ ]] and can only be accessed by a method.

For example:

var str = new String('example');

When inspecting variable str, I see the property [[PrimitiveValue]] has the example value, but I cannot access this property because it's internal. The only way to access it by the method toString() only.

My question is: how can I implement the custom object with that behavior?, having an internal property with [[ ]] surrounding and a method to access that property.



from How to implement object internal slot property

No comments:

Post a Comment