Created
September 16, 2014 17:16
-
-
Save timrwood/fcd0925bb779f4374a7c to your computer and use it in GitHub Desktop.
Immutable Moments
This file contains 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
An example here. http://jsfiddle.net/timrwood/tdkfqkdg/