Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Immutable Moments
(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]);
}
}));
@timrwood
Copy link
Author

timrwood commented Sep 16, 2014

@jehoshua02
Copy link

jehoshua02 commented Oct 24, 2014

Javascript is magic.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment