From: Tim Wood Date: Fri, 3 Feb 2012 18:17:44 +0000 (-0800) Subject: Adding docs for cloning moments #148 X-Git-Tag: 1.4.0~10 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d70752720ea28754992a21cff0d15b9eefeb48c6;p=thirdparty%2Fmoment.git Adding docs for cloning moments #148 --- diff --git a/sitesrc/docs.jade b/sitesrc/docs.jade index 1f05630a4..1a8f66ab0 100644 --- a/sitesrc/docs.jade +++ b/sitesrc/docs.jade @@ -43,6 +43,8 @@ block content a(href="#/parsing/now") Now li a(href="#/parsing/array") Javascript Array + li + a(href="#/parsing/clone") Cloning h2 a(href="#/manipulation") span Manipulation @@ -354,14 +356,36 @@ block content | var day = moment(Date.UTC.apply({}, array)); + a(name="/parsing/clone") + h3 + span Cloning + p All moments are mutable. If you want a clone of a moment, you can do so explicitly or implicitly. + code moment() + pre var a = moment([2012]);\n + | var b = moment(a); + | b.year(); // 2012 + p Additionally, you can call + code moment.fn.clone + | to clone a moment. + pre var a = moment([2012]);\n + | var b = a.clone(); + | a.year(2000); + | b.year(); // 2012 + + a(name="/manipulation") h2 span Manipulation p Once you have a Moment.js wrapper object, you may want to manipulate it in some way. There are a number of code moment.fn - | methods to help with this. + | methods to help with this. p All manipulation methods are chainable, so you can do crazy things like this. pre moment().add('days', 7).subtract('months', 1).year(2009).hours(0).minutes(0).seconds(0); + p It should be noted that moments are mutable. Calling any of the manipulation methods will change the original moment. + p If you want to create a copy and manipulate it, you should use + code moment.fn.clone + | before manipulating the moment. + a(href="#/parsing/clone") More info on cloning. a(name="/manipulation/add")