覆盖window.alert

For years the only bit of feedback web developers could get was via alert("{str}") calls. These days we have the web console but, in rare cases, we don't have a console and alert calls are our only window into a value at a given time.

多年来,Web开发人员只能通过alert("{str}")调用获得反馈。 如今,我们拥有Web控制台,但在极少数情况下,我们没有控制台,并且alert呼叫是我们在给定时间访问值的唯一窗口。

One problem: if an alert sneaks into production code, your site looks like it's been hacked. Your site looks like it's malware! To prevent any of those issues, you can add this snippet to your production build:

一个问题:如果alert潜入生产代码中,则您的网站看起来像被黑了。 您的网站看起来像是恶意软件! 为防止出现任何此类问题,您可以将此代码段添加到生产版本中:

window.alert = console.log

This tiny line of JavaScript could save your site from catastrophe. There are many cases for overriding native functionality and this is a great example!

这行很小JavaScript可以使您的网站免于灾难。 在很多情况下,本机功能都将被覆盖,这是一个很好的例子!

翻译自: https://davidwalsh.name/override-window-alert

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值