prototype constructor
のthis
にアクセスしようとしています。コンストラクタオブジェクトでこれにアクセスする
SomethingUseful.prototype = {
constructor: SomethingUseful,
init: init,
someFunction: someFunction,
mouseDownHandler: mouseDownHander.bind(this)
}
しかしthis
window
に等しいです。だから、私はbind(SomethingUseful)
を実行しようとしました。mouseDownHandler
に私がthis
を書き込むと、関数全体がプレーンテキストとしてログアウトするので、実際のmouseDownHandler
関数ではthis
にあるものは使用できません。
constructor
機能にSomethingUseful
のthis
にアクセスするための正しい方法は(再び、私はおそらく名前が間違っていましたし、私が行った場合、それを修正する、または私がコメントでお知らせ下さい)何ですか?
あなたは正確に何を達成しようとしていますか? 'this'の詳細な説明はこれを見てください。 @stottoverflow.com/questions/40722379/callback-with-this-confusion/40722549 –
@ScottMarcusこれを行うのではなく、 'this.mouseDownHandler = mouseDownHander.bind(this);'これを 'SomethingUseful .prototype = {'。これが明確になることを願っています。 – Jessica
[あなたのプロトタイプ定義は変です](http://stackoverflow.com/q/17474390/1048572)。また、プロトタイプ上のインスタンスにメソッドをバインドすることはできません。定義中にインスタンス( 'this')がなく、メソッドが共有されるためです。代わりにコンストラクタでそれを行います! – Bergi