I have a Javascript class inside my global.js like this:
class CustomModal extends ModalDialog {
constructor() {
super();
this.modals = [{
name: 'quick-select',
title: 'Quick Select',
},
{
name: 'main-menu',
title: 'Menu',
},
{
name: 'notify-me',
title: 'Notify When Back in Stock',
},
];
}
}
window.CustomModal = CustomModal;
Now I want to access the class properties from outside the class inside an inline script tag, like this:
<script>
document.addEventListener('DOMContentLoaded', function() {
console.log('window.CustomModal.modals', window.CustomModal.modals)
});
</script>
but I'm getting undefined
. What am I doing wrong?
I want to access properties and functions. I also want to change variables. My main goal is to add another modal to the array, like this:
<script>
document.addEventListener('DOMContentLoaded', function() {
window.CustomModal.modals.push({ name: 'new-modal', title: 'New Modal' });
});
</script>
Thanks in advance!