What is this construct ({ tick: ... }) called?
How it works?
An object initializer is made up of a series of property initializers (name: value
). The value in each property initializer is evaluated and then assigned to the property. The value of your tick
property is a function, but it could easily be a string, number, another object, whatever.
Part of which spec is this?
The object initializer is from the ECMAScript spec (ECMAScript being the technical name for the standardized language that we all call JavaScript). The current spec is the 5th edition but object initializers were there from the beginning.
The part taking the properties from that object initializer and adding them to the element object is from that very spec, the web components spec. See Section 5.2:
The properties of the last value of the script will be copied to a prototype object created for you. In the above example,
<tick-tock-clock>
elements will have a tick method.