What's the reasoning behind the extra restrictions in [[CanPut]]?

John-David Dalton john.david.dalton at gmail.com
Thu Dec 29 14:56:17 PST 2011


So I was digging through repairES5.js
http://code.google.com/p/google-caja/source/browse/trunk/src/com/google/caja/ses/repairES5.js#1427

and noticed that:

  var a = Object.freeze({ 'x': 1 });
  var b = Object.create(a);
  b.x = 2;
  b.x; // should still be 1

Then I dug into spec and noticed:
http://es5.github.com/#x8.12.4

so `b.x` remains 1 because the property 'x' of its [[Prototype]] is
writable: false.

Ok, so why all of that when you could simply do:

  var b = Object.create(a, {
    'x': {
      'configurable': true,
      'enumerable': true,
      'writable': true,
      'value': 2
    }
  });

or

  Object.defineProperty(b, 'x', {
    'configurable': true,
    'enumerable': true,
    'writable': true,
    'value': 2
  });

  b.x; // 2

- JDD


More information about the es-discuss mailing list