strange javascript property definition using polymer

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();

Answers


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?


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.


Need Your Help

Save string to the NSUserDefaults?

ios cocoa-touch nsuserdefaults

How to save a string into the NSUserDefaults?

PHP generating and naming html for calendar to mysql database

php mysql calendar

I have a PHP page where a user can select a month and then an html label and selection box will generate for each day of the month: