I would like to create a class that would work like for example built in BigInt. So I can do:
BigInt('111') BigInt('222').toString()
Please guide me on how to code it. I’m using NodeJS with vanilla JavaScript. Thank you so much in advance.
I would like to create a class that would work like for example built in BigInt. So I can do:
BigInt('111') BigInt('222').toString()
Please guide me on how to code it. I’m using NodeJS with vanilla JavaScript. Thank you so much in advance.
2
Answers
To achieve something like this, you will have to use factory functions instead of the usual class constructors. Here is an example:
There are several solutions.
It’s probably easiest to create a normal class and then a helper function that creates the object.
Another option is to use a helper function that calls Object.create