DEV Community

Discussion on: JavaScript prototypes by example

Collapse
 
somedood profile image
Basti Ortiz • Edited

That's a great question, Nicholas! It usually boils down to the discussion of "performance" and "best practices". It's often regarded to be a "bad practice" to tamper with the prototype—especially at runtime—because of the performance implications.

Moreover, the side effects of tampering with the prototype may introduce some unwanted bugs and security vulnerabilities.

For instance, let's say that you're using a third-party library. Wouldn't it be bad news if the library author tampered with the prototype of Object in a malicious manner? This type of attack is what's known as prototype pollution.

This is one of the reasons why ES6 classes were added: to provide a relatively "safer" way of tampering with the prototype.

So to finally answer your question, the reason why we use double underscores is to deter people from tampering with the prototype in the first place. Double underscores are scary to look at. By naming it that way, we are basically warning ourselves not to mess with it because of the performance and security implications.

Hope this answers your question! 😉