In ES5 style javascript, to override the toString method I would simply do the following:
function myFunction() {
}
myFunction.prototype.toString = function() {
return "My amazing function";
};
var myAmazingFunc = new myFunction();
console.log(myAmazingFunc);
In my current code I use ES6 and my object is now a class (which essentially is a function).
class MyAwesomeClass {
// awesome code goes here
}
What I have tried to do to override the toString method are the following:
class MyAwesomeClass {
toString() {
return "Awesome";
}
}
And also
class MyAwesomeClass {
// awesome code goes here
}
MyAwesomeClass.prototype.toString = function() {
return "Awesome";
};
Also without the prototype - but still it does not seem it's being called.
How is this possible in ES6 class?