I am creating a object using Object.create
and I want to add properties to it.
> var o = Object.create({});
undefined
> Object.defineProperty(o, "foo", {value: 43, enumerable: true});
{foo: 43}
> o
{foo: 43}
> o.foo
43
> for (var i in o) { console.log(i); }
foo
> Object.keys(o)
['foo']
> Object.defineProperty(o, "foo", {value: 43, enumerable: false });
TypeError: Cannot redefine property: bar
Q1) Why can't I redefine the property ?
> o.__proto__
{}
> o.prototype
undefined
Q2) Why is the prototype empty ? And why are these 2 values different i.e. {}
vs undefined
?
__proto__
. – Accomplish