Necesito exportar (para usar variables en otros scripts y otros archivos .js) el valor real de una variable dentro de una función, ¿cómo puedo hacer eso?
Las variables globales con valores cero están configuradas, cambian sus valores dentro de las funciones, necesito exportar estos valores solo después de ejecutar la función.
las variables que deben exportarse se comentan dentro de la función.
let numberOfTracks = null; let tracks = ''; let musicid = null; let dude = ''; let currentTrack = null; let pathForTrack = ''; const generateTracksBox = function () { for (let i = 1; i <= numberOfTracks; i++) { $(`<div class="container card chartsCard" data-musicid="${i}"> <img class="card-img-top" src="/AppMusic/assets/chartLogo/${i}.svg" alt="Card image cap"></img> <div class="card-body"> <h5 class="card-title">${tracks[i-1].split('-')[0]}</h5> <p class="card-text">${tracks[i-1].split('-')[1]}</p> </div> </div`).appendTo('.charts'); } const dude = $('.chartsCard'); for (let i = 0; i < dude.length; i++) { dude[i].onclick = function () { currentTrack = $(dude[i]).data('musicid'); //need to export location.href = "music/player.html"; } } } const getTracksArray = function () { let xhr = new XMLHttpRequest(); xhr.open('GET', `/AppMusic/assets/tracks`); xhr.responseType = 'text'; xhr.onload = function () { const pathsForTracks = new RegExp('(?<=href="\)(.+?)(?=")', 'g'); const nameOf = new RegExp('(?<=mp3">)(.+?)(?=.mp3)', 'g'); numberOfTracks = xhr.response.match(nameOf).length; // need to export tracks = xhr.response.match(nameOf) generateTracksBox() pathForTrack = xhr.response.match(pathsForTracks) // need to export } xhr.send(); }