Hi so I'm trying to learn a little more about prototyping and javascript and so lets say I have this code
String.prototype.getVal=function()
{
return ?
};
How would a string so that 'Spencer'.getVal()==='Spencer'
would I have to use this within the function and then iterate over each character in the object?
This is pointless but
It's pointless because you can just use
.toString()
directly.or
The
String
constructor, when invoked withoutnew
, basically returns the.toString()
value of its argument if it's an object.