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.
I am very unfamiliar with this structure, and with JS in general.
asked Mar 7, 2018 at 9:10
Metal Mathematician
1,4823 gold badges22 silver badges38 bronze badges
1 Answer 1
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>
default