How to rewrite or change the js default function. For example. Substr is a predefined function in javascript. I want to change it to return some other result.
Asked
Active
Viewed 36 times
-1
-
1yes, you can. have you tried anything? – Nina Scholz Feb 29 '20 at 09:53
-
Add part of the code that you have written and you the function that you want to override – Vala Khosravi Feb 29 '20 at 10:06
-
Can you share what you have tried so far? This helps others to help you better. – Utsav Patel Feb 29 '20 at 10:16
-
Does this answer your question? [Override function in JavaScript](https://stackoverflow.com/questions/11542192/override-function-in-javascript) – Utsav Patel Feb 29 '20 at 10:19
-
1`String.prototype.substr = () => {console.log('i am overridden')}` – glinda93 Feb 29 '20 at 13:56
1 Answers
0
Sounds like you are talking about prototypes:
String.prototype.show = function() {
alert(this);
};
"Hello!".show(); // Hello!

Reece Casey
- 154
- 5