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.

asked Mar 7, 2018 at 9:10

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>
answered Mar 7, 2018 at 10:07

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.