1
this
から:JS:ランタイムを取得し「この」実行時に設定されている関数内の外側の関数
var person = {
hello: function(thing) {
console.log(this, " says hello " + thing);
}
}
// the code:
person.hello("world");
// is equivalent to:
person.hello.call(person, "world");
がいることを取得するには、(オブジェクト)にバインドさ関数への参照から始めて、それが可能ですオブジェクト?何かのように:
var misteryFunction = person.hello;
misteryFunction.getMyRuntimeThis() // returns: person
'this'はメソッドが呼び出されるオブジェクトに動的にバインドされます。これは、 'misteryFunction'が' apply'、 'call'または' bind'でバインドされていない限り、それが受信者であると判断できないことを意味します。 – ftor