Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dz2 #7

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions Dz-2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/**
* Возвращает объект Event
*
* @param {String} name Название события
* @param {Number|Date} start Дата и время начала события
* @param {Number|Date} end Дата и время окончания события
* @param {String} destination Пункт назначения
* @param {String} priority Важность события
* @param {String} InfSource Источники информации о событии
* @param {boolean} ready Событие состоялось?
*
* @example
* Event("event",
* new Date('2012-01-01T12:00:00'),
* new Date('2012-01-01T14:00:00'),
* "Earth",
* "important",
* "http://www.world-newspapers.com/science.html",
* true)
*
* @return {Object}
*/
function Event(name, start, end, destination, priority, InfSource, ready) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Слишком много аргументов - подумай как уменьшить.

"use strict";
if (typeof start === "Date") {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if (typeof start === "Date") WAT? :) https://speakerdeck.com/u/azproduction/p/2-liektsiia?slide=45

В программировании есть хороший принцип лучше шире, чем глубже - те нужно избавляться от вложенных стейтментов и стараться спрямлять их.

if (typeof start !== "number") {
    throw new TypeError("error of start time format");
}

if (typeof end !== "number") {
     // ....
}
...

if (typeof end === "Date") {
if (typeof ready === "boolean") {
return {
"name": name || "event",
"start": +start || '2012-01-01T12:00:00',
"end": +end || '2012-01-01T14:00:00',
"destination": destination || "any place",
"priority": priority || "no important",
"InfSource": InfSource || "-",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

infSource

"ready": ready || false
};
} else {
throw new TypeError("error of end time format");
}
} else {
throw new TypeError("error of start time format");
}
}
}