Reputation: 49609
In the following code xFoo
will be an object that (or its prototype) has an actual property bar
with a value of 5 and it will will have an actual method foo()
. What kind of object notation is this? This is not how I define properties in ECMAScript 5. I would have expected that xFoo.bar
is an object that has a function get()
and that xFoo.foo
is an object that has a method value()
. What am I missing here?
var XFoo = document.registerElement('x-foo', {
prototype: Object.create(HTMLElement.prototype, {
bar: {
get: function () {
return 5;
}
},
foo: {
value: function () {
alert('foo() called');
}
}
})
});
var xFoo = new XFoo();
Upvotes: 0
Views: 73
Reputation: 664425
What kind of object notation is this? This is not how I define properties in ECMAScript 5.
Of course it is. Just have a look at the docs of ES 5 Object.create
. It uses the same property descriptors as Object.defineProperties
does.
Upvotes: 0
Reputation: 14304
Yes, my guess was correct:
Sorry, but have you at least tried to google javascript Object.create
?
Upvotes: 1