Using getters and setters Part 2

Search for a command to run...

No comments yet. Be the first to comment.
Setting the content of an element with a number formatted with Indian currency

Defining a property to an object using Object.defineProperty()

Using PhotoSwipe v5 plugin and vanilla JavaScript with AlpineJS replacing jQuery for a photogallery section. Use of script type="module"

Accessing a AlpineJS data in a vanilla JavaScript function out of the AlpineJS component
Alpine JS
15 posts
Content articles for AlpineJS (https://alpinejs.dev) - currently using alpinejs@3.15.11
This is second part in the series to make use of getters and setters in an AlpineJS object, that converts INR to USD.
Well, only a setter has been used here where a function call is made to the setter priceInINR when the textbox of the USD value changes. The setter changes the value of the product's (which is an argument to priceInINR) price_INR value.
x-on:input="$store.global_data.priceInINR = product"
And the setter :
set priceInINR(p)
{
const product = this.products.find(product => product.name === p.name);
product.price_INR = p.price_USD * 83;
},
Here's the full source code.
PS: 1 USD = 83 INR as of 17th February 2024.
Here's a more interactive example / demo : https://anjanesh.s3.amazonaws.com/demo/alpine/alpine-auto-update-variable-method-1.html