Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

values not being passed between functions

I’ve been using javascript for years and am expanding my knowledge but dont understand the behaviour in the following code (simplified for brevity):

page.html

$(document).ready(function() {
        Modal.show('full', 'Hello World!');
});

Modal.js

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

class Modal {
     show({ type, title = '' }) {
        var builtModal = this.build(type, title)
        // do something
    }

    build({ type, title }) {
       // do something
    }
}

In Modal.show, type == ‘full’ & title is correct but in Modal.build (called from Modal.show) type == undefined & title == "". I’m expecting the values to be set as per the calling function… Any ideas??

>Solution :

Since you’re using destructuring in the parameter lists, you need to pass objects to be destructured:

$(document).ready(function() {
    Modal.show({type: 'full', title: 'Hello World!');
});

class Modal {
    show({ type, title = '' }) {
        var builtModal = this.build({type, title})
        // do something
    }

    build({ type, title }) {
       // do something
    }
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading