Skip to content

How to inject a new argument for each generated listener instance? #316

Answered by djipco
digable1 asked this question in Q&A
Discussion options

You must be logged in to vote

I went back to your code and I think I spotted the problem. The problem is that you are not replacing the arguments array but rather mutating a single value inside it. It is akin to doing this (going back to my previous example):

const opts = {channels: [3, 5], arguments: ["foo", "bar"]};
const listeners = WebMidi.inputs[1].addListener("noteon", (e, arg1, arg2) => console.log(arg1, arg2), opts);
listeners[1].arguments[0] = "Hello";
listeners[1].arguments[1] = "World!";
console.log(listeners[0].arguments);
console.log(listeners[1].arguments);

In this case, the result will be:

Hello World!
Hello World!

This simply illustrates that all listeners are passed the same reference to the original a…

Replies: 6 comments 7 replies

Comment options

You must be logged in to vote
1 reply
@digable1
Comment options

Comment options

You must be logged in to vote
1 reply
@digable1
Comment options

Comment options

You must be logged in to vote
1 reply
@digable1
Comment options

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
4 replies
@digable1
Comment options

@djipco
Comment options

@digable1
Comment options

@djipco
Comment options

Answer selected by digable1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants