电台复活节_如何通过在控制台中隐藏复活节彩蛋使您的应用程序用户惊讶

电台复活节

by Ethan Ryan

由伊桑·瑞安(Ethan Ryan)

如何通过在控制台中隐藏复活节彩蛋使您的应用程序用户惊讶 (How to surprise your app’s users by hiding Easter eggs in the console)

I love console.logging(“stuff”).

我喜欢console.logging(“ stuff”)。

I do it throughout my apps, for debugging purposes and feature building purposes, and just for the sheer hell of it. It’s fun to log stuff to the console.

我在整个应用程序中都这样做,出于调试目的和功能构建目的,并且纯粹出于此目的。 将内容记录到控制台很有趣。

I even use console.warn() and console.error(), and console.table() if I’m feeling frisky.

如果我感到烦躁,甚至可以使用console.warn()console.error()以及console.table()

I like all the pretty colors they make in my console, and sometimes you want some messages to stand out more than others.

我喜欢它们在控制台中制作的所有漂亮颜色,有时您希望某些消息比其他消息更加突出。

But I realized while looking at my story generator app WordNerds yesterday than I was logging to the console in production mode.

但是我昨天在看故事生成器应用程序WordNerds时发现 ,与在生产模式下登录控制台相比,我意识到了这一点。

Uh-oh spaghetti-ohs.

哦,意大利面条,哦。

That’s a no-no. It could slow down the code unnecessarily, and more importantly, it could compromise my users’ email addresses! I was logging all my users’ usernames and email addresses. Not cool! Their passwords are encrypted of course but still, no bueno. I wouldn’t want any bad guys getting a a bunch of my users’ email addresses and spamming them crapola.

那是不对的。 它可能会不必要地降低代码速度,更重要的是,它可能会损害我的用户的电子邮件地址! 我正在记录所有用户的用户名和电子邮件地址。 不酷! 他们的密码当然是加密的,但仍然没有加密。 我不希望任何坏蛋得到我用户的电子邮件地址,并给他们发送垃圾邮件。

在生产模式下摆脱控制台日志 (Getting Rid of Console Logs In Production Mode)

Fixing it turned out to be easy. Sure, I could have gone through the codebase and commented out all my console.logs(), but that would be a pain, and some of them are serving important purposes in development mode.

修复它很容易。 当然,我可以遍历代码库并注释掉我的所有console.logs(),但这很痛苦,其中一些在开发模式下起着重要的作用。

Luckily there’s an easier, better way.

幸运的是,有一种更简便,更好的方法。

First I consulted some of the solutions to this problem listed on StackFlow, and then ultimately went with the first solution listed on this blog post.

首先,我咨询了 StackFlow上针对此问题的一些解决方案 ,然后最终采用了此博客文章中列出的第一个解决方案。

As some of the comments mentioned when someone listed this as a solution to the problem: “That’s a hack. Your [sic] wasting computation in production”

正如有人将其列为问题解决方案时提到的一些评论:“这是黑客。 您的[原文如此]浪费了生产中的计算量”

Good debate! I wasn’t too worried about calling an empty function several times and wasting some computation in production, so I went with this solution, because it’s easy to implement and solves my problem.

好辩论! 我不太担心多次调用空函数并浪费生产中的计算量,因此我选择了此解决方案,因为它易于实现并解决了我的问题。

Here’s how I did it, in the src/index.js file:

这是我在src / index.js文件中执行的操作:

Of course I could do this in any file, like the App component, or my StoryContainer component. Anywhere as long as it was before any console logs or warns or errors were being rendered. But it made sense to me to do it at the root.

当然,我可以在任何文件中执行此操作,例如App组件或StoryContainer组件。 只要在呈现任何控制台日志或警告或错误之前的任何时间。 但是从根本上讲,这对我来说很有意义。

I tested it in development by replacing ‘production’ with ‘development’, and it worked! No more messages in the console.

我在开发中通过将“生产”替换为“开发”来对其进行了测试,并且成功了! 控制台中没有更多消息。

将消息添加回控制台 (Adding Messages Back Into the Console)

But then I felt sad :(

但是后来我很难过:(

No more messages in the console? Seemed so sparse.

控制台中没有更多消息了吗? 看起来如此稀疏。

May as well have SOME messages for those curious, intrepid word nerds daring enough to open up the console.

对于那些大胆地打开控制台的好奇,勇敢的书呆子,可能还会收到一些消息。

So I added one back in, like a hidden Easter egg:

所以我又添加了一个,就像一个隐藏的复活节彩蛋 :

How’d I do this? Easy: since all my app’s calls to console.log(), console.warn(), and console.error() where being overwritten by empty functions, I simply added in a console.info()! It’s basically the same as a console.log(). Some of the differences are listed, and disputed, here.

我该怎么做? 容易:因为我的应用程序对console.log()console.warn()console.error()所有调用都被空函数覆盖,所以我只添加了console.info() ! 它基本上与console.log()相同。 这里列出了一些差异,并且有争议。

hello everybody! was a little boring though. I already had my app’s logged-in user’s name stored in state, so why not personalize my message?

hello everybody! 虽然有点无聊。 我已经将应用程序的登录用户名存储在状态中,那么为什么不个性化我的消息呢?

And if I’m gonna personalize my message, why not personalized a bunch of messages, and randomly return one every time a logged-in user inspects the console? Everyone likes finding Easter eggs!

而且,如果我要个性化我的消息,为什么不个性化一堆消息,并在每次登录用户检查控制台时随机返回一条消息? 每个人都喜欢找到复活节彩蛋!

That’s what I decided to do, and here’s how I did it:

那就是我决定要做的,这就是我的做法:

I’m rendering my Greeting component in my StoryContainer, so that whenever a logged-in user chooses to check out the console, they’ll see one of those friendly messages!

我将在StoryContainer中渲染我的Greeting组件,以便每当登录用户选择检出控制台时,他们将看到这些友好消息之一!

function getFriendlyMessage(nameString) {let messages = [`Hello ${nameString}, it's good to see you!`,`sup ${nameString}`,`hi there ${nameString}, you look awesome today!`,`hi there ${nameString}, you spectacular human being you!`,`you look awesome today ${nameString}!`,`hellllooooooo ${nameString}!`,`Hey ${nameString}, how's life?`,`Can you keep a secret, ${nameString}? You're my favorite!`,`Nothing to see here, ${nameString}.`,`Congratulations, ${nameString}! You've discovered the console ;)`,`have i told you lately that i love you, ${nameString}?`,`i knew you'd find this Easter egg eventually, ${nameString}...`,]var randomMessage = messages[Math.floor(Math.random() * messages.length)];return randomMessage
}

Coding is fun.

编码很有趣。

Thanks for reading, word nerds!

感谢您的阅读,书呆子!

翻译自: https://www.freecodecamp.org/news/how-to-surprise-your-apps-users-by-hiding-easter-eggs-in-the-console-3b6e9285e7e7/

电台复活节

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/393155.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

leetcode1267. 统计参与通信的服务器(dfs)

这里有一幅服务器分布图,服务器的位置标识在 m * n 的整数矩阵网格 grid 中,1 表示单元格上有服务器,0 表示没有。 如果两台服务器位于同一行或者同一列,我们就认为它们之间可以进行通信。 请你统计并返回能够与至少一台其他服务…

System类入门学习

第三阶段 JAVA常见对象的学习 System类 System类包含一些有用的字段和方法,他不能被实例化 //用于垃圾回收 public static void gc()//终止正在运行的java虚拟机。参数用作状态码,根据惯例,非0表示异常终止 public static void exit(int stat…

gulpfile php,Laravel利用gulp如何构建前端资源详解

什么是gulp?gulp是新一代的前端项目构建工具,你可以使用gulp及其插件对你的项目代码(less,sass)进行编译,还可以压缩你的js和css代码,甚至压缩你的图片,gulp仅有少量的API,所以非常容易学习。 gulp 使用 st…

ios jenkins_如何使用Jenkins和Fastlane制作iOS点播构建系统

ios jenkinsby Agam Mahajan通过Agam Mahajan 如何使用Jenkins和Fastlane制作iOS点播构建系统 (How to make an iOS on-demand build system with Jenkins and Fastlane) This article is about creating iOS builds through Jenkins BOT, remotely, without the need of a de…

菜鸟也学hadoop(1)_搭建单节点的hadoop

其实跟官方的教程一样 只是 我想写下来 避免自己搞忘记了,,,,好记性不如烂笔头 首先确认自己是否安装了 java, ssh 以及 rsync 没有装的直接就 apt-get install 了嘛,,,java的不一定…

SP703 SERVICE - Mobile Service[DP]

题意翻译 Description   一个公司有三个移动服务员。如果某个地方有一个请求,某个员工必须赶到那个地方去(那个地方没有其他员工),某一时刻只有一个员工能移动。只有被请求后,他才能移动,不允许在同样的位…

CF758 D. Ability To Convert 细节处理字符串

link 题意:给定进制数n及一串数字,问在此进制下这串数能看成最小的数(10进制)是多少(如HEX下 1|13|11 475) 思路:此题要仔细思考细节。首先要想使数最小那么必定有个想法是使低位的数尽可能大即位数尽可能…

java 可能尚未初始化变量,java - 局部变量“变量”可能尚未初始化-Java - 堆栈内存溢出...

我得到这个错误。线程“主”中的异常java.lang.Error:未解决的编译问题:rgb2无法解析为变量它总是导致错误的rgb2数组。 如何解决这个问题呢?BufferedImage img1 ImageIO.read(file1);BufferedImage img2 ImageIO.read(file2);int w img1.…

leetcode1249. 移除无效的括号(栈)

给你一个由 ‘(’、’)’ 和小写字母组成的字符串 s。 你需要从字符串中删除最少数目的 ‘(’ 或者 ‘)’ (可以删除任意位置的括号),使得剩下的「括号字符串」有效。 请返回任意一个合法字符串。 有效「括号字符串」应当符合以下 任意一条 要求&…

软件工程——个人课程总结

软件工程,我就是冲着软件这两个字来的,开始我觉得我们大多数人也是这样的,能开发一款属于自己的软件应该是我们人生中的第一个小目标八,在上学期学完java语言后,我们自认为自己已经具备了开发一款小软件的能力&#xf…

规则网络_实用的网络可访问性规则

规则网络by Tiago Romero Garcia蒂亚戈罗梅罗加西亚(Tiago Romero Garcia) 实用的网络可访问性规则 (Pragmatic rules of web accessibility that will stick to your mind) I first started to work with web accessibility back in 2015, at an American retail giant. It h…

8-python自动化-day08-进程、线程、协程篇

本节内容 主机管理之paramiko模块学习 进程、与线程区别python GIL全局解释器锁线程语法join线程锁之Lock\Rlock\信号量将线程变为守护进程Event事件 queue队列生产者消费者模型Queue队列开发一个线程池进程语法进程间通讯进程池 转载:  http://www.cnblogs.co…

部署HDFS HA的环境

> 环境架构部署规划: bigdata1 NameNode ResourceManager Zookeeper JournalNode failOverController bigdata2 NameNode ResourceManager Zookeeper JournalNode failOverController bigdata3 DataNode NodeManager Zookeeper bigdata4 DataNode NodeManager &g…

php layui 框架,Thinkphp5+Layui高颜值内容管理框架

Thinkphp5Layui高颜值内容管理框架TP5Layui高颜值内容管理框架,新增API模块Thinkphp5Layui响应式后台权限管理系统专注打造好用的框架,极速开发,高效灵活,从架构上兼顾系统复杂度的迭代与需求多变。代码结构清晰,接口开…

leetcode657. 机器人能否返回原点

在二维平面上,有一个机器人从原点 (0, 0) 开始。给出它的移动顺序,判断这个机器人在完成移动后是否在 (0, 0) 处结束。 移动顺序由字符串表示。字符 move[i] 表示其第 i 次移动。机器人的有效动作有 R(右),L&#xff…

在Angular专家Dan Wahlin的免费33部分课程中学习Angular

According to the Stack Overflow developer survey 2018, Angular is one of the most popular frameworks/libraries among professional developers. So learning it increases your chances of getting a job as a web developer significantly.根据2018年Stack Overflow开…

select查询语句执行顺序

查询中用到的关键词主要包含六个,并且他们的顺序依次为 select--from--where--group by--having--order by 其中select和from是必须的,其他关键词是可选的,这六个关键词的执行顺序 与sql语句的书写顺序并不是一样的,而是按照下面的…

Python的Virtualenv(虚拟环境)的使用(Windows篇)2

Python的Virtualenv(虚拟环境)的使用(Windows篇) 2018年04月13日 11:35:01 D_FallMoon 阅读数 771 版权声明:版权所有 装载请注明 …

Loadrunner常用15种的分析点

1.Vusers:提供了生产负载的虚拟用户运行状态的相关信息,可以帮助我们了解负载生成的结果。 2.Rendezvous(负载过程中集合点下的虚拟用户):当设置集合点后会生成相关数据,反映了随着时间的推移各个时间点上并…

leetcode1442. 形成两个异或相等数组的三元组数目

给你一个整数数组 arr 。 现需要从数组中取三个下标 i、j 和 k &#xff0c;其中 (0 < i < j < k < arr.length) 。 a 和 b 定义如下&#xff1a; a arr[i] ^ arr[i 1] ^ … ^ arr[j - 1] b arr[j] ^ arr[j 1] ^ … ^ arr[k] 注意&#xff1a;^ 表示 按位异…