0
我想在JS中傳遞一個對象(引入了一些jQuery)。 :)Javascript - 依賴注入和承諾
一旦promise.success
函數運行,我想調用FlappyBarHelper.getUserPropertyCount()
方法。我已經試過路過this.FlappyBarHelper
到:
return $.ajax({
type: "GET",
url: 'get-the-score',
flappy: this.FlappyBarHelper,
});
但仍然讓flappy
未定義在promise.success
我完整的代碼:
function Rating(FlappyBarHelper) {
this.FlappyBarHelper = FlappyBarHelper;
}
Rating.prototype.attachRaty = function(property_id)
{
var promise = this.getPropertyScoreAjax(property_id);
promise.success(function (data) {
$('#'+property_id).raty({
click: function (score, evt) {
$.ajax({
type: "GET",
url: '/set-the-score',
})
.done(function (msg) {
$('#extruderTop').openMbExtruder(true);
//**** FlappyBarHelper is undefined at this point ****///
FlappyBarHelper.getUserPropertyCount('.flap');
});
}
});
});
};
Rating.prototype.getPropertyScoreAjax = function(property_id)
{
return $.ajax({
type: "GET",
url: 'get-the-score',
});
}
漂亮的教科書答案。感謝您的詳細解釋。我還閱讀了「成功vs完成」的區別。 :) – Kiksy
不客氣! – Feugy