0

This is a follow-up to my previous post Adding JS to the checkout, which was answered nicely here.

It works fine, but now I have a problem that I want to add and call multiple JS functions, so I tried:

define([
  'jquery',
], function($){
 
    var hello = function()
    {
        alert('Bonjour Amir');

    }
    var print = function()
    {
        console.log('asdfgh');
    }
    return hello && print;
});

And in the template I call it like:

<script type="text/javascript">
    require(['jquery', 'checkoutjs'], function($, hello, print) {
        hello();
        print();
    });
</script>

But I get an error:

Uncaught TypeError: print is not a function

However, hello function is the one that does not execute.

enter image description here

I am very unfamiliar with this structure, and with JS in general.

1 Answer 1

0

Change your code as follows, that should work:

define([
  'jquery',
], function($){
    return {
        hello: function() {
            alert('Bonjour Amir'):
        },
        print: function() {
            console.log('asdfgh');
        }
    }
});


<script type="text/javascript">
    require(['jquery', 'checkoutjs'], function($, checkoutjs) {
        checkoutjs.hello();
        checkoutjs.print();
    });
</script>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.