In JavaScript, you could write
var someDate = new Date(2010, 6, 9);
Date.yesterday.date == someDate.date // true
Left out needless implementation details, but it's possible. Ok, there ya go :)
(function() {
function date(d) {
var year = d.getFullYear();
var month = d.getMonth();
var day = d.getDate();
return new Date(year, month, day);
}
Object.defineProperty(Date, 'yesterday', {
enumerable: true,
configurable: false,
get: function() {
var today = new Date();
var millisecondsInADay = 86400000;
var yesterday = new Date(today - millisecondsInADay);
return yesterday;
},
set: undefined
});
Object.defineProperty(Date.prototype, 'date', {
enumerable: true,
configurable: true,
get: function() {
return date(this).valueOf();
},
set: undefined
});
})();