I would like to be able to define an object that will evaluate to a primitive but also may have attached functions. Effectively the same way the "String" class works. Is there a way for me to extend the class without modifying the String prototype.
One use case for me would be like this:
class ID extends String{
constructor(len){
let value = 'Very unique id';
this.len = len;
this = value; //Or some other way of assigning the objects value
}
someRandomFunction(){
console.log('I was called');
}
}
const newId = new ID(10);
console.log(newId) // prints "Very unique id"
newId.someRandomFunction() // prints "I was called"
console.log(newId.len) // prints "10"