[英]How to select a property of an Object containing a class
Is it possible to select a property from an object containing a class like this below?是否有可能从 object 到包含 class 的属性 select,如下所示?
//Object
const voices = {
fmsynth: Tone.FMSynth,
amsynth: Tone.AMSynth,
synth: Tone.Synth
}
//my function to select the above synths
switch_synth(synth_id) {
const synth = new Tone.PolySynth(voices[synth_id], 6).toDestination();
console.log(voices[synth_id]);
}
In your code, call voices["fmsynth"]
or even voices.fmsynth
, to get Tone.FMSynth
.在您的代码中,调用
voices["fmsynth"]
甚至voices.fmsynth
以获取Tone.FMSynth
。
So your code seems to be doing the right thing, as long as you are calling switch_synth
with an appropriate synth_id
, eg所以你的代码似乎在做正确的事情,只要你用适当的
synth_id
调用switch_synth
,例如
switch_synth("fmsynth")
Are you getting an error, and if so, what error?您收到错误了吗?如果是,是什么错误?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.