I am writing a three.js application and need to access a variable called camera
, because whenever I click a button I want to move the camera up and down.
However, my buttons are nested callbacks and I am wondering how can I accessing the variable within the callbacks?
e.g.
let camera = ...
let circles = document.querySelectorAll('circle');
circles.forEach(function(c){
c.onclick = function(e){
circles.forEach(function(circle){
circle.classList.remove('active');
circle.classList.add('disabled');
});
e.target.classList.add('active');
e.target.classList.remove('disabled');
if (e.target.id === "example"){
camera.position.set(0,0,0) //camera not defined
}
debugger;
}
});
I am a little confused why I can access the circles
varaible at the debugger point, however it keeps saying camera
is undefined.