DEV Community

Cover image for Coding 🤦‍♂️
Phippsy
Phippsy

Posted on

Coding 🤦‍♂️

Today I actually thought Firefox had disabled window.alert();.

I almost never use alert() in my code. In this instance I was using alert() as a place holder and took the opportunity to share my impeccable sense of humor.

alert('Just kidding.  You can't do that right now');
Enter fullscreen mode Exit fullscreen mode

Hilarious Alert Message

Hilarious, right? (don't you roll your eyes at me!)

So I tried it out in my app... nothing happened! I check console to be greeted by:

Uncaught TypeError: alert is not a function
Enter fullscreen mode Exit fullscreen mode

WTF?

I was really ready let rip at Firefox. The world needs to know about this. Heads were gonna roll! I started searching to gather evidence to see when they had disabled window.alert(). Couldn't find anything. After more time than I care to admit, I saw a Stack Overflow answer explaining how to disable window.alert() in code:

alert = function() {};
Enter fullscreen mode Exit fullscreen mode

That's when it occurred to me that this was a PEBKAC error (Problem Exists Between Keyboard And Chair).

Could it be more likely that I caused this problem rather than the possibility that a widely adopted browser had suddenly disabled window.alert()?

I searched my code base and found this gem:

alert={};
Enter fullscreen mode Exit fullscreen mode

Yep. That's 20+ years javascript experience right there folks.

It would make me feel better if you guys could maybe share your own facepalm moments in the comments! Mind you, I'm gonna feel pretty stupid if the comments are empty...

I hope you've enjoyed my first DEV post.

Top comments (8)

Collapse
 
bfuculsion profile image
Benjamin Follis

It's sorta your fault. But no namespaces or write protection on built in functions is the environment's fault.

Collapse
 
michaelphipps profile image
Phippsy

It's not sorta my fault. It's TOTALLY my fault!

Collapse
 
jamesthomson profile image
James Thomson

Yep. A simple 'use strict'; would have saved you.

We've all been there though. Typos or camel case used to get me sometimes, thankfully eslint (and typescript at times) negates about 99% of this sort of stuff.

Thread Thread
 
michaelphipps profile image
Phippsy

I see what you are doing here. While you're point out the errors of my ways, you're avoiding sharing your own coding 🤦‍♂️.

Share your shame! (If you dare) :D

Thread Thread
 
jamesthomson profile image
James Thomson

Can't think of a specific blunder lately, but I'll be sure to let you know when it happens 😂

Collapse
 
bfuculsion profile image
Benjamin Follis

Eh, I'm of the opinion if your environment needs special flags to prevent you from doing obviously dangerous things then it's the one that's mostly at fault. Environments should require flags to LET you do obvious dangerous things.

Collapse
 
sainig profile image
Gaurav Saini

SIGH here it is
We use custom es6 classes on top of mongoose models as a wrapper to sort of abstract out the existence of mongodb from our route handlers. I had to store additional info on one of the models so I wrote logic for it and tested out my api endpoint.
I WAS SHOCKED - no new info in the database
I thought I didn’t save my work or didn’t wait for the server restart (yes, I do that sometimes), but it was not the case

After banging my head and pulling my hair for around 1 hr I realised that I didn’t add the field to my es6 wrapper classes so they prevented the data from being passed on to the mongoose model. Silly me

Collapse
 
michaelphipps profile image
Phippsy

GAh! I use a similar style architecture for my backend in PHP and MySQL. I've had similar experience as a result, although maybe not 1 hour. (Probably longer!)

Something annoying is that once I solve problems like this my colleague always says "Well done! You worked it out" (in a sincere way, not sarcastic). Drives me nuts. I shouldn't have missed it in the first place! I could have spent the time watching TV and been just as productive.