電臺復活節_如何通過在控制臺中隱藏復活節彩蛋使您的應用程序用戶驚訝

電臺復活節

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.pswp.cn/news/393155.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/393155.shtml
英文地址,請注明出處:http://en.pswp.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;^ 表示 按位異…