I have this class:
var color = function(r, g, b, a) {
this.r = r
this.g = g;
this.b = b;
this.a = a;
this.toString = function() {
if (!isset(a)) return "rgb("+parseInt(r)+","+parseInt(g)+","+parseInt(b)+")";
return "rgba("+parseInt(r)+","+parseInt(g)+","+parseInt(b)+","+a+")";
}
}
If i want the string output I have to type (for example) console.log(colorInstance.toString())
but is there a way to make the toString() method be called implicitly each time the receiving function expects a string value? So I could write console.log(colorInstance) instead?
""+colorvalueOf.