From 15eadc86545a91c9e4f63008c0ab2d70e96283c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=93=D1=80=D0=B8=D0=BE=D0=B3=D0=BE=D1=80=D1=8C=D0=B5?= =?UTF-8?q?=D0=B2=D0=B0=20=D0=98=D1=80=D0=B8=D0=BD=D0=B0?= Date: Sun, 28 Oct 2012 15:17:29 +0600 Subject: [PATCH 1/2] =?UTF-8?q?=D0=94=D0=B72?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Создала функцию Event. Но JSLint выдает ошибки: 1. Unexpected 'typeof'. Use '===' to compare directly with undefined. в строчке 29. Но === не выполнит проверку на undefined 2. Missing 'new'. в строчках 58 и 62. Не понимаю, что не так --- Event.js | 79 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 Event.js diff --git a/Event.js b/Event.js new file mode 100644 index 0000000..fbebe5e --- /dev/null +++ b/Event.js @@ -0,0 +1,79 @@ +/*jslint plusplus: true, browser: true, devel: true */ +/** + * Возвращает объект Event + * + * @param {Object} NewEvent Объект - событие + * @param {Number|Date} NewEvent.start Начало события + * @param {Number|Date} NewEvent.end Конец события + * @param {String} [NewEvent.name="Событие"] Имя события + * @param {String} NewEvent.place Место события + * @param {Number} NewEvent.rating Рейтинг события от 0 до 5 + * @param {String} NewEvent.comment комментарий, описание события + * @param {String} NewEvent.link ссылка + * + * @example + * Event({ + * start: new Date('2011-10-10 14:48:00'), + * end: new Date('2011-10-10 15:48:00'), + * name: "Совещание", + * place: "офис 111", + * rating: 5, + * comment: "взять отчет!!!", + * } + * ) + * + * @return {Object} + */ +function Datatype(data) { + "use strict"; + if (typeof data === 'undefined') { + return false; + } + if (!data.getTime) { + return false; + } + if ('Invalid Date' === data) { + return false; + } + return true; +} +/** +* возвращает true, если data имеет тип дата и она корректна +*/ +function ratingtype(rating) { + "use strict"; + if (typeof rating !== 'number') { + return false; + } + if (rating > 5 || rating < 0) { + return false; + } + return true; +} +/** +* возвращает true, если rating - число от 0 до 5 +*/ +function Event(NewEvent) { + "use strict"; + if (!Datatype(NewEvent.start)) { + alert(NewEvent.start + " не является датой!"); + return; + } + if (!Datatype(NewEvent.end)) { + alert(NewEvent.end + " не является датой!"); + return; + } + if (!ratingtype(NewEvent.rating)) { + alert("введите рейтинг от 0 до 5"); + return; + } + return { + "start": NewEvent.start, + "end": NewEvent.end, + "name": NewEvent.name || "Событие", + "place": NewEvent.place, + "rating": NewEvent.rating, + "comment": NewEvent.comment, + "link": NewEvent.link + }; +} \ No newline at end of file From 80e6e8ac3d695d40615307dc55674bd4b26731b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=93=D1=80=D0=B8=D0=BE=D0=B3=D0=BE=D1=80=D1=8C=D0=B5?= =?UTF-8?q?=D0=B2=D0=B0=20=D0=98=D1=80=D0=B8=D0=BD=D0=B0?= Date: Sun, 28 Oct 2012 17:46:47 +0600 Subject: [PATCH 2/2] =?UTF-8?q?=D0=B8=D0=B7=D0=BC=D0=B5=D0=BD=D0=B8=D0=BB?= =?UTF-8?q?=D0=B0=20datatype?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Event.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Event.js b/Event.js index fbebe5e..6c80f94 100644 --- a/Event.js +++ b/Event.js @@ -24,7 +24,7 @@ * * @return {Object} */ -function Datatype(data) { +function datatype(data) { "use strict"; if (typeof data === 'undefined') { return false; @@ -55,11 +55,11 @@ function ratingtype(rating) { */ function Event(NewEvent) { "use strict"; - if (!Datatype(NewEvent.start)) { + if (!datatype(NewEvent.start)) { alert(NewEvent.start + " не является датой!"); return; } - if (!Datatype(NewEvent.end)) { + if (!datatype(NewEvent.end)) { alert(NewEvent.end + " не является датой!"); return; }