Please tell me how to make the function getGameSound return the result of the method thisAudio.onloadedmetadata in getGameSound duration. The result of the method should be the duration of setTimeout.
TheGunman.prototype.getGameSounds = function (action) { var audioTmpl = '<audio id=":action" src=":path:action:expansionSound" autoplay></audio>'; var getAudio = audioTmpl.replace(/:action/gi, action).replace(/:path/gi, this.pathSound).replace(/:expansionSound/gi, this.expansionSound); this.GameObject.frame.append(getAudio); var thisAudio = document.querySelector('#' + action); // результат выполнения этого метода надо вернуть в функцию из которой вызывался getGameSound return thisAudio.onloadedmetadata = function () { return thisAudio.duration * 1000; } }; TheGunman.prototype.startGame = function () { var __self = this; var duration = // длительность звука вернувшего из функции getGameSounds this.getGameSounds('intro'); setTimeout(function () { __self.CreateNewEnemy(); }, duration);