Why some attribute names start with double underscore in JavaScript?

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 )

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)