var App = App || {};
App = {
getDataFromServer: function(){
var self = this,
deferred = $.Deferred(),
requests = [];
requests.push($.getJSON('request/ajax/url/1'));
requests.push($.getJSON('request/ajax/url/2'));
$.when.apply(jQuery, requests).done(function(xhrResponse) {
return deferred.resolve(xhrResponse.result);
});
return deferred;
},
init: function(){
this.getDataFromServer().done(_.bind(function(resp1, resp2) {
// Do the operations which you wanted to do when you
// get a response from Ajax, for example, log response.
}, this));
}
};
App.init();
Используя момент, вы можете сделать следующее ...
<script src="//cdnjs.cloudflare.com/ajax/libs/moment.js/2.8.4/moment.min.js"></script>
<script>
var now = moment(),
begin = moment().subtract(1, 'days').startOf('day'),
end = moment().add(2, 'days').endOf('day')
document.write(now.isAfter(begin) && now.isBefore(end))
</script>
С moment@2.15.1
существует метод isBetween
, который позволяет проверить, существует ли дата между двумя датами, с инклюзивной и эксклюзивной поддержкой.
Проверить http: // momentjs .com / docs / # / query / is-between /
Пример:
moment(dateToCheck).isBetween(startDate, endDate);