I'm doing migration from 0.5 to 1.0.
While reading, I notice 2 different way on declaring attributes, using hostAttributes
and properties
.
What are difference between those 2 ?
The properties of synthetic polymers depend on their structures. For example, HDPE consists of straight chains packed together densely and is hard and strong. On the other hand, LDPE consists of branched chains, and is much softer and more flexible. How does the structure of a polymer affect its properties?
Examples of polymers are rubber, plastics, and nylon. The properties of a polymer are affected by the structure, type of monomer units from which polymers are formed, and other factors. Polymers have different physical and chemical properties, which are listed below:
Some DOM properties don’t possess corresponding attributes. Some HTML attributes don’t possess corresponding properties. Some HTML attributes, like ‘class’, possess 1:1 mapping to properties. Let us take a look at some quick examples to demonstrate the differences between attributes and properties. Example: Consider the following HTML code snippet.
associated with it. Default attributes (non-user-defined) change when corresponding property changes and vice-versa. Non-custom attributes (like id, class, etc.) have 1:1 mapping to the properties. We use ‘className’ to access (get or set) the ‘class’ property because ‘class’ is a reserved keyword in JavaScript.
Host attributes are attributes that do not match to an element's corresponding Javascript property (which you declare in properties
). This includes attributes like class
, tabindex
, data-*
attributes, aria-roles, etc. To declare them during create-time, you must set them in the hostAttributes
object. If you are going to bind values into them, you must use $=
(which calls Element.setAttribute
) rather than =
.
Sources:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With