K
karl.lopes
Hi,
I am trying to understand assignment in javascript. Assume ECMAScript 5.
My Question is why does step 4 in the note below work. I would expect it to fail.
1. //Create an Object...
var buffer = Object.create(Object.prototype);
2. //Add a property
Object.defineProperty(buffer, "__data__", {value:[],writable:false,enumerable:false,configurable:false});
Note in setp 2 the property is completely closed to any modification.
In particular...
3.var buffer_copy = Object.create(buffer);
//I would expect the line below to fail.. Since in Step 2 __data__ is made //writable false. BUT It works and the assignment does take place.
//As per JavaScript the Definitive Guide pg 122: If o inherits a read-only //property named x, for example, then the assignment is not allowed.
4.buffer_copy.__data__ = [];
I am trying to understand assignment in javascript. Assume ECMAScript 5.
My Question is why does step 4 in the note below work. I would expect it to fail.
1. //Create an Object...
var buffer = Object.create(Object.prototype);
2. //Add a property
Object.defineProperty(buffer, "__data__", {value:[],writable:false,enumerable:false,configurable:false});
Note in setp 2 the property is completely closed to any modification.
In particular...
3.var buffer_copy = Object.create(buffer);
//I would expect the line below to fail.. Since in Step 2 __data__ is made //writable false. BUT It works and the assignment does take place.
//As per JavaScript the Definitive Guide pg 122: If o inherits a read-only //property named x, for example, then the assignment is not allowed.
4.buffer_copy.__data__ = [];