我剛剛開始使用dateJS,它似乎是一個很好的lib,但我顯然錯過了一些東西(可能是一個愚蠢的錯誤),但在我的函數中,我需要3個日期:clickedDate,weekStart & weekEnd。但使用dateJS我似乎覆蓋每個變量。有人能指出我的錯誤嗎?dateJS覆蓋變量
var clickDate = myDate;
console.log(clickDate);
var weekStart = Date.parse(clickDate).last().monday();
console.log(clickDate);
var weekEnd = Date.parse(clickDate).next().sunday();
console.log(weekEnd);
console.log('break');
console.log(clickDate);
console.log(weekStart);
console.log(weekEnd);
控制檯顯示以下
Date {Wed Nov 30 2011 00:00:00 GMT-0700 (US Mountain Standard Time)}
Date {Mon Nov 28 2011 00:00:00 GMT-0700 (US Mountain Standard Time)}
Date {Sun Dec 04 2011 00:00:00 GMT-0700 (US Mountain Standard Time)}
break
Date {Sun Dec 04 2011 00:00:00 GMT-0700 (US Mountain Standard Time)}
Date {Sun Dec 04 2011 00:00:00 GMT-0700 (US Mountain Standard Time)}
Date {Sun Dec 04 2011 00:00:00 GMT-0700 (US Mountain Standard Time)}
[SSCCE](http://sscce.org)。一個很棒的JavaScript SSCCE工具:http://jsfiddle.net。什麼是'myDate',一個字符串?順便說一句,你是否想'console.log(clickDate)'連續兩次? –
[It works for me](http://jsfiddle.net/LJJKn/)。 –
使用更多全局變量 –