Here is the method I employ to create my module:
var $ = $ || false;
if (typeof jQuery !== 'undefined') {
$ = jQuery;
}
var conversekitTemplates = {
test1: function() {
alert('greetings everybody');
},
test2: function() {
$('body').css('background-color', '#fff');
},
test3: 123,
test4: 440,
test5: function() {
var a = apple;
},
test6: 'h1>' + a + '</h1>'; //how do I access the value of variable a here?
};
This is how I invoke it:
require.config({
paths: {
'jquery': '/media/jui/js/jquery.min',
'templates': '/plugins/system/conversekit/templates'
}
});
require(['jquery', 'templates'], function($) {
$('body').html('hello');
// conversekitTemplates.test1();
console.log(conversekitTemplates.test6);
});
I did refer to this source: Accessing variables from other functions without using global variables
However, I am not keen on passing the value from one function to another specifically. I want any function that wishes to utilize a value from another function to be able to call upon it.