Dave Reiß
Dave Reiß

Reputation: 3

Can I call this function in an arrow-function?

I program with the spotify API.. the error are these 2 functions, I dont know how I call the 'setVolume' function in this arrow-function. Is this possible or is the Code wrong?

I don't know any further. Here is my code:

player.on('player_state_changed', state => {

   //... SOME CODE ...

   

   function setVolume(value) {
       player.setVolume(value).then(() => {
           console.log('Volume updated!');
       });
   }

});

(1) In the console I tried this:

setVolume(0.5)

(2) In the console I tried this:

player.on(setVolume(0.5))

~ and I got this error message: "player is not defined"

So how can I call the setVolume function from the console?

Upvotes: 0

Views: 44

Answers (1)

T.J. Crowder
T.J. Crowder

Reputation: 1074258

So how can I call the setVolume function from the console?

Fundamentally, you can't, not least because there isn't just one of them. There's a new setVolume function created every time the state change callback is run. Each of those functions is local to that state change callback and not accessible outside it. It would possible to have a global variable that you updated with the latest copy of the function each time one was created, but that's not likely to be a good idea. The function is presumably local for a reason.

Upvotes: 1

Related Questions