How to extend the Javascript Date object?

前端 未结 12 2105
失恋的感觉
失恋的感觉 2020-12-08 14:50

I\'m trying to subclass/extend the native Date object, without modifying the native object itself.

I\'ve tried this:

    var util = require(\'util\')         


        
12条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-08 15:33

    You can also use github.com/loganfsmyth/babel-plugin-transform-builtin-extend

    Example:

    import 'babel-polyfill'
    
    export default class MyDate extends Date {
        constructor () {
            super(...arguments)
        }
    }
    

提交回复
热议问题