I would like to know if there is a way to return a JS class's value by default instead of of reference to the class object itself. Let's say, for example, I want to wrap a string..
var StringWrapper = function(string) {
this.string = string;
};
StringWrapper.prototype.contains = function (string) {
if (this.string.indexOf(string) >= 0)
return true;
return false;
};
var myString = new StringWrapper("hey there");
if(myString.contains("hey"))
alert(myString); // should alert "hey there"
if(myString == "hey there") // should be true
doSomething();
and now I want to get string just by using myString rather than myString.string. Is this doable somehow?
Edit
I took the console.log(myString) out of the question, because console.log has behavior that I didn't originally take into account. This question isn't about log.
console.log??new MyClass()construct? It sounds like a "normal" function would work better.