Answer the question
In order to leave comments, you need to log in
How to make the base class inherit?
I'm trying to create my own class that will inherit from String, but there are problems.
This option works in the browser but does not work in React Native
but for some reason this option does not work anywhereclass MyString extends String { }
function MyString() { }
MyString.prototype = Object.create(String.prototype)
Answer the question
In order to leave comments, you need to log in
There is such. Opera, for example, shouts:
According to the specification , toString throws an exception if this is not a string, that is, roughly
String.prototype.toString = function() {
if (typeof this === 'string')
return this.valueOf();
else
throw new TypeError();
};
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question