This is how I create my module:
var $ = $ || false;
if (typeof jQuery !== 'undefined') {
$ = jQuery;
}
var conversekitTemplates = {
test1: function() {
alert('hello everyone');
},
test2: function() {
$('body').css('background-color', '#fff');
},
test3: 123,
test4: 440,
test5: function() {
var a = apple;
},
test6: 'h1>' + a + '</h1>'; //how to use the value of variable a here?
};
This is how I'm calling it:
require.config({
paths: {
'jquery': '/media/jui/js/jquery.min',
'templates': '/plugins/system/conversekit/templates'
}
});
require(['jquery', 'templates'], function($) {
$('body').html('helo');
// conversekitTemplates.test1();
console.log(conversekitTemplates.test6);
});
I did refer here: Accessing variables from other functions without using global variables
But I don't want to pass the value from one function to another in particular. I want to let any function that want to use a value from a function to be able to call it.