Why is Google Closure Compiler failing on my ES6 object which extends Date()?

风格不统一 提交于 2019-12-05 15:39:29

Date is not subclassable in ES5. So what you want is not possible in ES5 environments in the first place.

The transpiled code cannot work in ES6 environments either. From the specification

The Date constructor is designed to be subclassable. It may be used as the value of an extends clause of a class definition. Subclass constructors that intend to inherit the specified Date behaviour must include a super call to the Date constructor to create and initialize the subclass instance with a [[DateValue]] internal slot.

Without calling super it won't work. Date.call(this); doesn't do the trick. Basically, if you transpile code to ES5, subclassing built-in types is a no-go.

So no, it's not a problem of Google Closure.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!