I'm implementing a function that receives an argument which it needs to convert to its string representation.
If a given object implements a toString()
method, then the function should use it. Otherwise, the function can rely on what the JavaScript implementation offers.
What I come up with is like this:
var convert = function (arg) {
return (new String(arg)).valueOf();
}