Here is the code
<script>
String.prototype.testthing = function() {
return "working";
}
alert(String.testthing());
</script>
When I open this page I get the error below
Uncaught TypeError: Object function String() { [native code] } has no method 'testthing'
I cannot figure out why. I’ve extended the Array prototype with no issues.
The code you’ve shown correctly extends the
Stringprototype. However you’re trying to call a method on a function withString.testthingand not on astringinstance.If you actually want to call methods off of the
Stringconstruct then you need to extend the prototype onFunction