this
関数を呼び出すが、実行して関数を呼び出すときにコンテキストを「デフォルト」値に設定するメソッドはありますfn()
か?
このメソッドは、apply()と同様に、配列を受け入れ、単一の要素を引数として関数に渡す必要があります。
emitter = new EventEmitter();
args = ['foo', 'bar'];
// This is the desired result:
emitter.emit('event', args[0], args[1], ...);
// I can do this using apply, but need to set the context right
emitter.emit.apply(emitter, 'event', args);
// How can I trim the context from this?
emitter.emit.???('event', args);
編集:これを明確にするために、呼び出された関数内にある値に注意します-グローバルオブジェクトなどではなく、this
実行時に持つ「通常の」コンテキストである必要があります。emitter.emit()
そうでなければ、これは時々物事を壊します。