惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

腾讯CDC
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
P
Proofpoint News Feed
D
DataBreaches.Net
D
Docker
云风的 BLOG
云风的 BLOG
大猫的无限游戏
大猫的无限游戏
月光博客
月光博客
J
Java Code Geeks
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
罗磊的独立博客
Martin Fowler
Martin Fowler
U
Unit 42
Engineering at Meta
Engineering at Meta
IT之家
IT之家
Vercel News
Vercel News
B
Blog RSS Feed
人人都是产品经理
人人都是产品经理
博客园 - Franky
博客园 - 【当耐特】
Stack Overflow Blog
Stack Overflow Blog
G
Google Developers Blog
MongoDB | Blog
MongoDB | Blog

NBlog

NBlog - 软件工程和工程师们的未来在何方? NBlog - Gitlab EE 破解手册 NBlog - Gitlab EE 破解手册 NBlog - 又是一年高考季 NBlog - 又是一年高考季 NBlog - 心浮气躁的AI时代 NBlog - 心浮气躁的AI时代 NBlog - 我的2025 NBlog - 我的2025 NBlog - 一位高考数学73的学生证明了黎曼猜想 NBlog - 一位高考数学73的学生证明了黎曼猜想 NBlog - 2017 夏 NBlog - 2017 夏 NBlog - OPanel: 较大型开源个人项目初尝试 NBlog - OPanel: 较大型开源个人项目初尝试 NBlog - [博客更新] 博客添加AI生成内容标识 NBlog - [博客更新] 博客添加AI生成内容标识 NBlog - 为什么我感觉Minecraft越来越无聊了? NBlog - 为什么我感觉Minecraft越来越无聊了? NBlog - 对Abc曲谱标记语言的探索 NBlog - 对Abc曲谱标记语言的探索 NBlog - 域名弃用公告 NBlog - 域名弃用公告 NBlog - [博客更新] 转移至next.js,并重新设计整个网站 NBlog - [博客更新] 转移至next.js,并重新设计整个网站 NBlog - 我的歌单 NBlog - 我的歌单 NBlog - 证明简谐运动的周期公式 NBlog - 证明简谐运动的周期公式 NBlog - [聽后有感] 二
一个控制台小游戏
NriotHrreion · 2020-09-23 · via NBlog
这是一个很粗糙控制台游戏. 如果你好奇这个游戏的操作原理, 那么你可以去这个工程的 [Github仓库](https://github.com/NriotHrreion/Console-game) 看看, 或者继续往下看. ## 原理 在源代码 **lib.js** 中, 你可以在 `setCommand()` 方法中找到下面的代码: ```javascript // command 是要设置的指令名称 // func 要执行的指令程序 setCommand(command, func) { window[command] = command; // 将指令名称设为全局变量 Object.defineProperty(window, command, { // 设置 getter get: func, enumerable: true }); } ``` **代码解释** 将要设置的指令定义为全局变量, 接着为这个全局变量设置getter. 这样, 当你在控制台输入指令时, getter便会执行刚刚设置的程序.