2016-11-03 8 views

答えて

2

jQuery's $.proxy()

$.get("test.php").then( 
    $.proxy(this.good,this), 
    $.proxy(this.fail,this) 
); 

または.bind()

$.get("test.php").then( 
    this.good.bind(this), 
    this.fail.bind(this) 
); 
+1

Additonallyをした

$.get('https://jsonplaceholder.typicode.com/posts') .then(function(response) { console.log(this); }.bind(this)) 

1

また、渡された関数に 'この' をバインドするネイティブJavaScriptを使用することができます。

ような何か:私はあなたが繰延オブジェクトを制御するとき、あなたはdeferred.resolveWith(thisArg)を呼び出すことができる場合には、この例でフィドル https://jsfiddle.net/8xk0s4na/

関連する問題