I found a difference in how JavaScript adds properties to objects. Code example below shows it.
var t1 = {
x: 1
}
var t2 = {}
Object.defineProperty(t2, 'y', {
value: 2,
configurable: false,
writable: false
});
Object.setPrototypeOf(t1, t2);
t1.y = 100;
t1.y; --> returns 2
Object.defineProperty(t1, 'y', { value: 100 });
t1.y; --> return 100
t1 has t2 as its prototype. I make sure the property 'y' added to t2 is non configurable and non writable. When I try to add y to t1 by using t1.y = 100, y is not added to the object and t1.y still return 2. However, when using defineProperty, y does get added to t1.
I figure it has something to do with how JavaScript treats the prototype chain but i can't wrap my head around it...