Setters are no longer called when setting properties in object initializers: what does this mean?

This JS MDN page says the following:

JavaScript Note 1.8.1

Starting with JavaScript 1.8.1, setters are not a longer call when setting properties in the object and in the Initializers array.

I just can't understand what this is trying to tell me.

+5
source share
2 answers

I think this relates to the issue of JSON capture. Take a look

To send an answer from this deleted question :

According to the specification, neither Array ( EcmaScript 5.1 ยง11.1.4 ) nor object literals ( EcmaScript 5.1 ยง11.1.5 ) should be hijackable:

  • They call the "standard built-in constructor with this name", not what you could overwrite in window.Array or window.Object
  • They use [[defineOwnProperty]], which absolutely does not care about any setters on Object.prototype .

This should not be an issue at this time in browsers compatible with ES 5.1.

+4
source

This piece of code:

 var o = {}; o.seven = 7; 

and this piece of code:

 var o = { seven: 7 }; 

usually equivalent; but if preceded by this piece of code:

 Object.prototype.__defineSetter__('seven', function(x) { alert(x); }); 

then only the first will warn 7 (because the setter is called o.seven = 7 , but not o = { seven: 7 } ), and only the latter actually sets o.seven to 7 .

+7
source

All Articles