I want to create a new method to built-in objects Array and Date. I have seen everywhere on the internet that using Object.prototype is evil. Also, I read that subclassing built-in objects is not supported in babel. So how can I add new methods to built-in objects using es6?
There is nothing stopping you from creating subclasses that extend built-in classes, in fact, it's often a good baseline solution for minor changes.
class Foo extends Date { bar() { console.log(this); } } const foo = new Foo(); foo.bar();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.