Search code examples
javascriptecmascript-5

[[Set]] attribute of the object


While reading Principles of Object-Oriented JavaScript I came across the following line on end of page 32 of free chapter on author's website :

When a property is first added to an object, JavaScript uses an internal method called [[Put]] on the object. The [[Put]] method creates a spot in the object to store the property.

When a new value is assigned to an existing property, a separate operation called [[Set]] takes place. This operation replaces the current value of the property with the new one.

The author talks here of changing value of named data property which happens due to internal attribute of object called [[Set]]. I looked into ECMA 5 and found [[Get]] , [[Put]] but no such attribute [[Set]]. However [[Set]] attribute is available for named accessors in object.

My question is there any object internal attribute called [[Set]] ? If not then how does changing of value of data property happens ?


Solution

  • That's because [[Put]] was renamed to [[Set]] in ECMAScript 6.

    Specifically, from Early ES6 Working Drafts,

    • Rev 12 (November 22, 2012 Draft)

      Replaced [[Get]]/[[Put]] with [[GetP]]/[[SetP]].

    • Rev 14 (March 8, 2013 Draft)

      Rename [[GetP]] to [[Get]] and [[SetP]] to [[Set]]

    In ES5 there was a [[Put]] internal method and no [[Set]]. In ES6 there was a [[Set]] internal method and no [[Put]]. More or less, they behave the same.