简体   繁体   中英

How to enforce no-extend-native in es6 compiled using babel?

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM