Explanation of the idea :
I would like to build a class that can be called like a function without initializing it as an instance. For example, I want to create a class named logger
and use it in two ways: the first way is logger("some text")
and the second way is logger.info("some text")
using dot notation.
Problems :
The issues I am facing are that I do not want to create a method inside the class that represents the first way, because this method will appear during dot notation. For example:
class logger {
// if i want it to represents the first way: logger("some text")
// this will appear if i write logger.log, and i don't want that.
static log(){}
// this method what i want it to be accessible in object pattern.
// example: logger.info()
static info(){}
}
there’s also another problem:
When I try to access the logger class, it shows me other methods and properties. I want only the methods and properties that I have defined to appear in dot notation. if i write logger.
, it will show me apply
and call
and bind
I attempted to create a logger
class that could be called both as a function (logger("some text")
) and using dot notation (logger.info("some text")
) without initializing it as an instance. but there’s a methods appear if i use dot notation