ppowell777
Well-Known Coder
prototypes.js:
index.html:
This very simple code somehow fails, and I don't know why. I want to be able to run myString.doStuff(str), but the function is never defined within the String prototype. I honestly have never had this problem in the past. Please help, as this is breaking an entire website.
Thanks
JavaScript:
if (!String.prototype.doStuff) {
String.prototype.doStuff = (str) => {
// do stuff to this with str
return this.substring(0, this.length());
};
alert(typeof doStuff); // returns "undefined" and I don't know why
}
index.html:
HTML:
<html>
<head>
<script src="scripts/prototypes.js"></script>
</head>
<body>
Blah blah blah..
<!-- STUFF -->
</body>
</html>
This very simple code somehow fails, and I don't know why. I want to be able to run myString.doStuff(str), but the function is never defined within the String prototype. I honestly have never had this problem in the past. Please help, as this is breaking an entire website.
Thanks