From 0c21d67486665d7889547a4614ef18e3307d2af0 Mon Sep 17 00:00:00 2001 From: dirk Date: Thu, 20 Jun 2019 22:07:44 +0800 Subject: [PATCH] diary on Jun 20. --- diary.js | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 diary.js diff --git a/diary.js b/diary.js new file mode 100644 index 0000000..d42c30f --- /dev/null +++ b/diary.js @@ -0,0 +1,36 @@ +const DATA = new Date(2019, 6, 20); +const WEATHER = "sunny"; +const LOCATION = "shenzhen"; + +class Dirkwei { + constructor(name) { + if (!Dirkwei.instance) { + this.name = name; + this.todoList = []; + Dirkwei.instance = this; + } + return Dirkwei.instance; + } + + cookAfterWork(food) { + console.log(`${this.name} make ${food}`); + return this; + } + + addTempThingsTodo(...fncs) { + this.todoList.push(...fncs); + } + + finishTodoList() { + this.todoList.forEach(task => task()); + } +} + +Dirkwei.instance = undefined; + +const me = new Dirkwei("dirkwei"); +me.addTempThingsTodo( + () => console.log("read PHP code"), + () => console.log("finish my homework.") +); +me.cookAfterWork("fried dumplings").finishTodoList();