Monday, June 3, 2024
100
rated 0 times [  107] [ 7]  / answers: 1 / hits: 24124  / 13 Years ago, fri, july 1, 2011, 12:00:00

I see some attributes of some objects in JavaScript start with double underscore. For example, something like __defineGetter__ or __defineSetter__ or __proto__.
Is it a convention defined ECMAScript specification? Or maybe it's just a convention in the developer community?


More From » double-underscore

 Answers
5

These are properties defined by the specific browser and are not defined by ECMAScript.



Therefore, name collision needs to be avoided. If they called the property defineGetter, then there would be no guarantee that the website's code didn't already define a property by that same name -- and that would cause many problems. However, appending two underscores has become the defacto way to define browser specific properties (since it's much less likely some website will use that convention).



You may notice that other browsers start using the same naming convention as others (like using __proto__), but that's still not universally guaranteed between all browsers (eg, IE does not define the __proto__ property).



Also: the convention of using two underscores for system-defined identifiers (as opposed to programmer-defined identifiers) harkens back a long time, so I don't know when that convention started -- At least as long as C++ (see http://en.wikipedia.org/wiki/Name_mangling#Simple_example )


[#91406] Wednesday, June 29, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
campbelljonahb

Total Points: 247
Total Questions: 97
Total Answers: 110

Location: Jordan
Member since Wed, Jun 17, 2020
4 Years ago
;