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! 😉
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
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
ofObject
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! 😉