Is there any way to return a custom type instead of "object"? On the next case, I would want to return i.e. "i16"
>function Int16(v) { this.v=v }; var n = new Int16(10);
>typeof n
"object"
>Object.prototype.toString.call(n)
"[object Object]"
No, you can’t overload typeof — it always returns the base type.
In the given example, you could use the constructor property:
function Int16(v) { this.v=v };
> var n = new Int16(10);
> n.constructor.name
"Int16"
> n.constructor === Int16
true
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With