window.addEventListener("click", function(e) {
let oscillator = null;
if(condition) {
oscillator = audioCtx.createOscillator();
oscillator.start();
} else {
oscillator.stop(); // 현재는 oscillator = null
}
});
대충 이런 구조에서.. 클릭이벤트로 oscillator를 키고 끄고를 하려 하는데.
if 절에서 변경한 oscillator(audioCtx.createOscillator())를
else절의 oscillator에도 반영되게 할 수 있는 방법은 없겠지?
피곤해서 그런가 엄청 빡대가리처럼 멀리 돌아가는 느낌인데..................
아 그냥 재귀함수로 돌리다가, 끄고 싶을 때 해제하는 식으로 하면 되려나
let oscillator = null 를 두줄 위로