I have two JavaScript files on my custom theme. One file has functions that need to be used on the other file. What I have below doesn’t work. This is the error I get.
Uncaught ReferenceError: test is not defined.
jQuery will be used on both files.
file1.js
/**
* @file
* UI behaviors
*/
(function ($, Drupal) {
'use strict';
$(document).ready(function () {
function test(){
console.log('hello'):
}
});
})(jQuery, Drupal);
file2.js
/**
* @file
* UI behaviors
*/
(function ($, Drupal) {
'use strict';
$(document).ready(function () {
test();
});
})(jQuery, Drupal);
customtheme.libraries.yml
scripts:
js:
js/file1.js: {}
js/file2.js: {}
customtheme.info.yml
libraries:
- 'customtheme/scripts'