Skip to content
Advertisement

How can show the singleton object’s attribution?

We can show instance’s attribution with dir function.

JavaScript

Now create a class with metaclass method:

JavaScript

Show Cls’s _instances attrubution:

JavaScript

Why no string _instances in dir(Cls)?

JavaScript

Advertisement

Answer

Because it’s stored on the metaclass.

JavaScript

To be clear, this has nothing to do with the singleton aspect.

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement