From ed92c892c7493ea39b4d6505d2be595170067703 Mon Sep 17 00:00:00 2001 From: shenyu616 Date: Fri, 21 Jun 2019 15:22:58 +0800 Subject: [PATCH] . --- NoteBook.js | 35 +++++++++++++++++++++++++++++++++++ main.js | 10 ++++++++++ 2 files changed, 45 insertions(+) create mode 100644 NoteBook.js create mode 100644 main.js diff --git a/NoteBook.js b/NoteBook.js new file mode 100644 index 0000000..38e8ac5 --- /dev/null +++ b/NoteBook.js @@ -0,0 +1,35 @@ +export default class NoteBook { + constructor (props) { + const {pages, type} = props; + this._bookTotalPages = pages; + this._bookType = type; + this.logs = []; + } + + init (author, bookName) { + this._noteBookCreateDate = Date.now (); + this._author = author; + this._bookName = bookName; + this.contexts = []; + } + + /** + * add new context + * @param {title,date,content,weather} params + */ + addContext (params) { + this.contexts.push (params); + this._addLog (params); + } + + _addLog (params) { + const {title, date} = params; + const log = `${this._author} add an article 「${title}」 to ${this._bookName} at ${date}`; + this.logs.push (log); + } + + showHistory () { + console.log (this.logs); + return this.logs; + } +} diff --git a/main.js b/main.js new file mode 100644 index 0000000..123a3d2 --- /dev/null +++ b/main.js @@ -0,0 +1,10 @@ +import NoteBook from './NoteBook'; + +const samOneYearDiary = new NoteBook ({pages: 365, type: 'diary'}); +samOneYearDiary.init ('Sam', "Sam's one year diary"); +samOneYearDiary.addContext ({ + title: "Sam's one day", + date: '2019-06-21', + weather: 'rainy', + content: 'Still have a lot of work to do 😢', +});