0

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();
bitbonk
  • 48,890
  • 37
  • 186
  • 278

2 Answers2

1

Yes, my guess was correct:

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/create#Parameters

Sorry, but have you at least tried to google javascript Object.create?

kirilloid
  • 14,011
  • 6
  • 38
  • 52
0

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.

Bergi
  • 630,263
  • 148
  • 957
  • 1,375