Javascript – JS Function with fetch : Access once at a time
I have the following JS function that fetches data and put in a window.data property: function fetchData() { if (window.data) { return Promise.resolve(window.data) } else { return fetch('http://example.com/data.js') .then(response => response.json()) .then(json => window.data = json) } } The code…