From 5ae589303f1ad7ac71a10a3d3ea951ff42482232 Mon Sep 17 00:00:00 2001 From: AmazRan Date: Sat, 22 Jun 2019 15:19:02 +0800 Subject: [PATCH] =?UTF-8?q?css&js=E8=A7=84=E8=8C=83=E4=BD=9C=E4=B8=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- index.js | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 index.js diff --git a/index.js b/index.js new file mode 100644 index 0000000..6adefef --- /dev/null +++ b/index.js @@ -0,0 +1,51 @@ +const PRICE_MAP = Object.freeze({ + '鸡蛋': 1, + '香蕉': 2, + '苹果': 3, + '拉面': 20 +}) + +function wakeUpByAlarm(clockTime) { + console.log("起床时间:" + clockTime); +} + +function buyFoodAndEat(shopList = []) { + shopList.forEach(food => { + if (PRICE_MAP[food]) { + console.log(`花费了${PRICE_MAP[food]}元吃了一份${food}`) + } + }) +} +class Work { + constructor() { + console.log("开始一天新的工作") + } + pause() { + console.log("暂停一下手头工作") + } + continue () { + console.log("继续手头工作") + } + finish() { + console.log(`完成今天工作,赚得${this._getPay()}元`) + } + _getPay() { + return 100; + } +} + +function sleep(ms) { + return new Promise(resolve => setTimeout(resolve, ms)) +} + +(async function main() { + wakeUpByAlarm("8点30分"); + let foodForBreakfast = ['鸡蛋', '香蕉']; + buyFoodAndEat(foodForBreakfast); + let todayWork = new Work(); + todayWork.pause(); + let foodForLunch = ['拉面'] + buyFoodAndEat(foodForLunch) + todayWork.continue(); + todayWork.finish(); +})()