Properties
Initial value
The initial
value of a property can be declared in the props
object:
class MyExample extends Wafer {
static get props() {
return {
count: {
type: Number,
initial: 10,
},
};
}
}
When an element is connected to the DOM (in the connectedCallback
method), the initial value of a property is calculated as follows:
- If the property has already been set, this will be its initial value - i.e. any attribute or
initial
value will be ignored. - If the property is unset (
undefined
) and an attribute with the same name as the property is present, the initial value will be set to the parsed value of the attribute using the propertytype
rules. Theinitial
value will not be used. - If the property is unset (
undefined
) and there is no attribute with the same name, theinitial
value will be used, if present.
Next: Reflection
Previous: Types