Why some attribute names start with double underscore in JavaScript? -
i see attributes of objects in javascript start double underscore. example, __definegetter__
or __definesetter__
or __proto__
. convention defined ecmascript specification? or maybe it's convention in developer community?
these properties defined specific browser , are not defined ecmascript.
therefore, name collision needs avoided. if called property definegetter
, there no guarantee website's code didn't define property same name -- , cause many problems. however, appending 2 underscores has become defacto way define browser specific properties (since it's less website use convention).
you may notice other browsers start using same naming convention others (like using __proto__
), that's still not universally guaranteed between browsers (eg, ie not define __proto__ property
).
also: convention of using 2 underscores "system-defined" identifiers (as opposed programmer-defined identifiers) harkens long time, don't know when convention "started" -- @ least long c++ (see http://en.wikipedia.org/wiki/name_mangling#simple_example )
Comments
Post a Comment