-
-
Save camsong/401932916a9925d21576 to your computer and use it in GitHub Desktop.
Immutable Moments
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function (root, factory) { | |
"use strict"; | |
if (typeof define === 'function' && define.amd) { | |
define(['moment'], factory); | |
} else if (typeof exports === 'object') { | |
module.exports = factory(require('moment')); | |
} else { | |
factory(root.moment); | |
} | |
}(this, function (moment) { | |
"use strict"; | |
function wrap (name) { | |
var old = moment.fn[name]; | |
moment.fn[name] = function () { | |
return old.apply(this.clone(), arguments); | |
}; | |
} | |
var methods = 'add subtract startOf endOf'.split(' '); | |
for (var i = 0; i < methods.length; i++) { | |
wrap(methods[i]); | |
} | |
})); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment