我正在写一个音乐相关的程序,并希望在我的对象中有对象作为属性。我知道可以一个一个做,但我想要一条捷径。这是我想要做的,我知道不行。什么是正确的方法?可能吗?如何在JavaScript中使用对象属性创建对象类?
function OctaveNote(note, value) {
this.firstOctave = note + 1.value = value;
this.secondOctave = note + 2.value = value + 12;
this.thirdOctave = note + 3.value = value + 24;
}
或者
function OctaveNote(note, value) {
this.firstOctave = note + 1;
this.firstOctave.value = value;
this.secondOctave = note + 2;
this.secondOctave.value = value + 12;
this.thirdOctave = note + 3;
this.thirdOctave.value = value + 24;
}
这样C = new OctaveNote ("C", 0);
让我知道C3.value = 24
和我没有写单个对象为所有11个音符,99行,每倍频程!
我不确定第一个可以工作。什么是1.value? –
'C3.value'是什么意思?你的意思是'C.thirdOctave.value'? – xqwzts