Posts

Showing posts with the label __proto__

__proto__ in ECMAScript 6

The property __proto__ (pronounced “ dunder proto ”) has existed for a while in most JavaScript engines. This blog post explains how it worked prior to ECMAScript 6 and what changes with ECMAScript 6. For this blog post, it helps if you know what prototype chains are. Consult Sect. “ Layer 2: The Prototype Relationship Between Objects ” in “Speaking JavaScript”, if necessary. __proto__ prior to ECMAScript 6 Prototypes Each object in JavaScript starts a chain of one or more objects, a so-called prototype chain . Each object points to its successor, its prototype via the internal property [[Prototype]] (which is null if there is no successor). That property is called internal , because it only exists in the language specification and cannot be directly accessed from JavaScript. In ECMAScript 5, the standard way of getting the prototype p of an object obj is: var p = Object.getPrototypeOf(obj); There is no standard way to change the prototype of an existing object, but you can ...

The text “__proto__” can break a webapp

[This post is part of a series on the special property __proto__ ] The text “__proto__” can still break webapps if it appears somewhere in the content, as I was reminded of today, via Domenic Denicola and Peter van der Zee . The breakage The following webapps are susceptible to “__proto__”-induced breakage: The classic – Google Docs: For a while, if you typed in “__proto__” at the beginning of a document in Google Docs then it would hang . Current – Twitter: If you click on @__proto__ in a tweet then the profile summary that comes up only has a title bar, but no content. You also get “slow script” dialogs in Firefox. You can try it out in this tweet . Why? __proto__ is a special property of JavaScript objects [1] . Therefore, if you use an object as a map from strings to values, you must not use the string "__proto__" as a key. That is one of several things that you have to watch out for when using objects this way [2] . __proto__ is only supported in some brow...