は、私はこの方法があります:私は地元のPlayOscillator
機能番目に(クラスから)これを参照する必要typescriptのメソッドのローカル関数内で "this"を使う方法は?
export class WebAudioApiProvider {
private _Oscillators: OscillatorNode[] = [undefined,undefined];
PlayOscillator(hz: number, durationInSeconds: number = 3){
// clear the timeout (if there was one)
clearTimeout(this._timeOutContainer);
console.info("_activeOscillatorIndex: " + this._activeOscillatorIndex);
switch (this._activeOscillatorIndex) {
// There are no active oscillators
case -1:
prepareOscillators(0);
break;
case 0:
prepareOscillators(1, 0);
break;
case 1:
prepareOscillators(0, 1);
break;
default:
break;
}
function prepareOscillators (indexToConnect: number, indextoDispose?: number)=>{
console.dir(this);
var success: boolean = false;
if (indextoDispose !== undefined && this._Oscillators[indextoDispose] !== undefined){
console.dir(this._Oscillators[indextoDispose]);
console.log("this._Oscillators["+indextoDispose+"] is NOT undefined, it will be stoped and saved as undefined");
// disconnect the current oscillator
this._Oscillators[indextoDispose].stop();
this._Oscillators[indextoDispose] = undefined;
}
}
}
}
を、私はlet PlayOscillator = (param,param) => {}
として割り当てしようとしたが、それはうまくいきませんでした。
正しい方法は何ですか?私はパラメータとして "this"を入れる必要がありますか? PlaOscillator(1, 0 , this)
?
は '' PlayOscillator'でthis'は、問題ないはずです。あなたはそれをやっていますか? –
いいえ、私はそうは思わない...私はconsole.dir "これ"私は "未定義"を得る – distante