Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Extend a String class in ES6

Tags:

People also ask

Can you extend the string class?

You can now extend classes in the . NET framework. In fact you can extend any class in which you can access!

How do you extend a class in JavaScript?

The extends keyword is used to create a child class of another class (parent). The child class inherits all the methods from another class. Inheritance is useful for code reusability: reuse properties and methods of an existing class when you create a new class.

How to extend Object in JavaScript?

The extends keyword can be used to extend the objects as well as classes in JavaScript. It is usually used to create a class which is child of another class. Syntax: class childclass extends parentclass {...}


I can write the following in ES5:

String.prototype.something=function(){
  return this.split(' ').join('');
};

How do I do the same thing in ES6 using the new features?

I know that this is also a valid ES6. I want to know whether there's any other way of implementing such functions in ES6 which is shorter?
The above function is just an example.